注册 登录
编程论坛 ASP技术论坛

l链表的问题

sunmingchun 发布于 2010-09-10 17:06, 477 次点击
各位大侠帮我看看这个程序怎么出现这样的结果。
#include<stdio.h>
#include<malloc.h>
struct student
{
    int num;
    char name[20];
    float grade[4];
    struct student *next;
};
struct student *creat()
{
    struct student *p,*q,*head;
    printf("请您输入各学生的学号,姓名,三科成绩及三科总分:\n");
    printf("如果想结束输入请输入 0 结束:\n ");
    p=(struct student *)malloc(sizeof(struct student));
    scanf("%d,%s,%f,%f,%f,%f",&p->num,p->name,&p->grade[0],&p->grade[1],&p->grade[2],&p->grade[3]);
    head=p;
    while(p->num!=0)
    {
        q=(struct student *)malloc(sizeof(struct student));
        printf("请您输入各学生的学号,姓名,三科成绩及三科总分:\n");
        printf("如果想结束输入请输入 0 结束:\n ");
        scanf("%d,%s,%f,%f,%f,%f",&q->num,q->name,&q->grade[0],&q->grade[1],&q->grade[2],&p->grade[3]);
        p->next=q;
        p=q;
    }
    p->next=0;
    return head;
}
    void print(struct student * head)
    {
      struct student *p;
       p=head;
      while(p!=0)
      {
        printf("%d  %s  %.2f  %.2f  %.2f  %.2f\n",p->num,p->name,p->grade[0],p->grade[1],p->grade[2],p->grade[3]);
        p=p->next;
      }
    }
    void main()
    {
        struct student * head;
        head=creat();
        print(head);
    }
我输入1,fdgdf,50,50,50,150
怎么输出这样的结果
只有本站会员才能查看附件,请 登录

2 回复
#2
wangjy5002010-09-10 18:53
肯定发错地方了!
#3
sunmingchun2010-09-10 21:23
回复 2楼 wangjy500
??????????????
发错地方了?
你看了吗
1