代码如下:
#include
#include
struct students
{
char name[10];
char number[10];
int score;
struct students *next;
};
int main()
{
int i,j,k;
struct students stu[5],*head,*p;
char n[10],no[10];
for(i=0;i {
printf("input the information of %dth student:\n",i+1);
scanf("%s%s%d\n",n,no,&stu[i].score);
strcpy(stu[i].name,n);
strcpy(stu[i].number,no);
}
head=&stu[0];
stu[4].next=NULL;
for(i=0;i {
stu[i].next=&stu[i+1];
}
p=head;
printf("students list:\n");
while(p!=NULL)
{
printf("%s\t%s\t%d\n",p->name,p->number,p->score);
p=p->next;
}
}
实际运行结果如下奇怪:
scanf("%s%s%d\n",n,no,&stu[i].score);
->
scanf("\n%s%s%d",n,no,&stu[i].score);