为了账号安全,请及时绑定邮箱和手机立即绑定

静态链表错哪了?

静态链表错哪了?

C
溯源1 2017-01-12 10:15:53
#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 反对 回复 2017-01-13
  • 1 回答
  • 0 关注
  • 1027 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信