#include "stdio.h" struct student { long num; float score; struct student * next; };void main(){ struct student stu1,stu2,stu3; struct studentn * head,*p; stu1.num=001;stu1.score=56; stu1.num=002;stu1.score=77; stu1.num=003;stu1.score=99; head=&stu1; stu1.next=&stu2; stu2.next=&stu3; stu3.next=NULL; p=head; while(p!=NULL) { printf("%ld,%5.1f\n",p->num,p->score); p=p->next; } }
1 回答
已采纳
岂可奈何
TA贡献5条经验 获得超3个赞
定义结构体指针时 student 写成 studentn
定义成员变量是,全部是 stu1的,没有stu2和stu3
程序:
#include <stdio.h>
struct student
{
long num;
float score;
struct student * next;
};
void main()
{
struct student stu1,stu2,stu3;
struct student * head,*p;
stu1.num=001;stu1.score=56;
stu2.num=002;stu2.score=77;
stu3.num=003;stu3.score=99;
head=&stu1;
stu1.next=&stu2;
stu2.next=&stu3;
stu3.next=NULL;
p=head;
while(p!=NULL)
{
printf("%ld,%5.1f\n",p->num,p->score);
p=p->next;
}
}
- 1 回答
- 0 关注
- 1044 浏览
添加回答
举报
0/150
提交
取消