69,371
社区成员
发帖
与我相关
我的任务
分享
#include<stdio.h>
#include<string.h>
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<5;i++)
{
printf("input the information of %dth student:\n",i+1);
scanf("%s%s%d",n,no,&stu[i].score); /* delete \n*/
strcpy(stu[i].name,n);
strcpy(stu[i].number,no);
}
head=&stu[0];
stu[4].next = NULL;
for(i=0;i<4;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中的回车符;