当前位置: 代码迷 >> C语言 >> 高手来啊,动态链表,不知道哪里有问题。
  详细解决方案

高手来啊,动态链表,不知道哪里有问题。

热度:181   发布时间:2008-04-14 23:23:38.0
高手来啊,动态链表,不知道哪里有问题。
以下程序编译无错,但是运行时第一次输入数据后,提示debug error.
高手帮忙改下,并解释下啊 

/* Note:Your choice is C IDE */
#include "stdio.h"
#include "malloc.h"
#define null 0
#define len  sizeof(struct student)

struct student /*定义结构体*/
{long num; float score;struct student *next;};
int n;
struct student *creat(void)/*定义建立动态链表的函数*/
{ struct student *head;
    struct student *p1,*p2;
    n=0;
    p1=p2=(struct student *)malloc(len);
    printf("please input then student's date:\n");
    scanf("%ld,%f",&p1->num,&p1->score);
    while(p1->num!=0)
    {n=n+1;
        if(n==1)head=p1;
        else p2->next=p1;
        p2=p1;
        
        p1=(struct student *)malloc(len);
        printf("please input then student's date:\n");
        scanf("%ld,%f",&p1->num,&p1->score);
    
        }
    
    p2->next=null;
    return(head);
    
    
    }
main()
{struct student *head;
    head=creat();
   
}

[[it] 本帖最后由 zyhfbim1a9 于 2008-4-15 00:34 编辑 [/it]]
搜索更多相关的解决方案: 链表  student  struct  

----------------解决方案--------------------------------------------------------
没有启动浮点计算!
----------------解决方案--------------------------------------------------------
  相关解决方案