求各位大虾帮我看看这个程序哪里错了~~~~先谢了

2025-05-17 23:18:08
推荐回答(1个)
回答(1):

你是不是用VS在编C程序?所以有scanf("%s",&cho);的问题?这个问题我也遇到过,换成cho=getchar();试一试。

不管luru往哪里添加新节点,只要head是全局变量luru就不需要返回值,因为要添加的链表只有一个而已。就像这样:

void luru(){
char cho;
struct student *p;
do{
if(head==0){
head=(struct student *)malloc(sizeof(struct student));
head->next=0;
inscanf(head);
}
else{
p=head;
while(p->next!=0){
p=p->next;
}
p->next=(struct student *)malloc(sizeof(struct student));
p=p->next;
p->next=0;
inscanf(p);
}
printf("continue to input student data?Y/N");
cho=getchar();
}while(cho=='Y'||cho=='y');
}