首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

关于指针追加的有关问题 急 .

2012-02-20 
关于指针追加的问题 急 ...结构如下structstud{charnumber[20]charname[10]charclas[10]charmath[10]c

关于指针追加的问题 急 ...
结构如下
struct   stud
{
char   number[20];
char   name[10];
char   clas[10];
char   math[10];
char   chinese[10];
char   english[10];
stud   *   next;
};
stud   *ps1;
stud   *hd;
我想在指针结尾再添加一条记录
hd=head;
                  while(hd)   //把指针走到最后
                  ps1=new   stud;
for(int   i=0;i <10;i++)
{
ps1-> number[i]=string[i];
ps1-> name[i]=nm[i];
ps1-> clas[i]=cs[i];
ps1-> math[i]=ma[i];
ps1-> chinese[i]=ch[i];
ps1-> english[i]=en[i];
}
hd-> next=ps1;
hd=ps1;
hd-> next=NULL;
编译都没错但执行后   报   程序遇到问题需要关闭  

我想问下   如何   在指针的最后(hd-> next==NULl)追加新的内容使指针(hd-> next=p1)   ,ps1-> next=NUll  


[解决办法]
老大:while(hd) //把指针走到最后 hd = hd-> next; 你这样最后hd是NULL的,还怎么能hd-> next=ps1;再指向新结点ps1????

while(hd-> next) //把指针走到最后
hd = hd-> next;

热点排行