关于c语言的问题

#include
#include
#include
struct stu
{int num;
char name[10];
int score;
struct stu *next;
};
stu*creat()
{int a;
char b[10];
int c;
stu *h,*s,*r;
h=(stu*)malloc(sizeof(stu));
r=h;
printf("请输入学生的学号,姓名,分数(输入-1时结束):");
scanf("%d",&a);
gets(b);
scanf("%d",&c);
while(a!=-1)
{s=(stu*)malloc(sizeof(stu));
s->num=a;
strcpy(s->name,b);
s->score=c;
r->next=s;
r=s;
scanf("%d",&a);
if(a==-1)break;
gets(b);
scanf("%d",&c);
}
r->next=NULL;
return(h);
}
void print(stu*head)
{
stu *p;
p=head->next;
if(p==NULL)printf("链表是空的");
else do{printf("%d\n",p->num);
puts(p->name);
printf("%d\n\n",p->score);
p=p->next;
}while(p!=NULL);
printf("结束");
}
int main()
{stu*head;
head=creat();
print(head);
}
stu*creat()
{int a;
这里要是没嫌前有参数,是不是需要void啊?芹厅清

stu *p;
p=head->next;
这里p的赋值不对吧

建立链表有固伏渗定的格式,套用就可以,感觉你写的不怎么合理
把gets 换成 scanf("%s"闷世虚...) 应该返氏就可以了。
这两个函数放在一起会出蚂燃问题。
关于c语言的问题
← 上一篇: 下一篇: →