标题:各位大神,请问我的动态链表程序怎么运行崩溃
只看楼主
JackBrian
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2015-2-13
结帖率:50%
已结贴  问题点数:20 回复次数:1 
各位大神,请问我的动态链表程序怎么运行崩溃
#include <stdio.h>
#include <stdlib.h>
#define LEN sizeof(struct Date)
struct Date
{
    int num;
    int score;
    struct Date *next;
};
int n;
struct Date *creat(void)
{
    struct Date *head;
    struct Date *p1,*p2;
    p1=p2=(struct Date *)malloc(LEN);
    scanf("%d,%d",&p1->num,&p1->score);
    n=0;
    head=NULL;
    while(p1->num!=0)
    {
        n=n+1;
        if(n==0) head=p1;
        else p2->next=p1;
        p2=p1;
        p1=(struct Date *)malloc(LEN);
        scanf("%d,%d",&p1->num,&p1->score);
    }
    p2->next=NULL;
    return(head);
}

int main()
{
    struct Date *pr;
    pr=creat();
    printf("\nnum=%d\nscore=%d",pr->num,pr->score);
    return 0;
}
搜索更多相关主题的帖子: 链表程序 动态 include 
2015-04-15 09:59
z_j_j_1
Rank: 4
等 级:业余侠客
威 望:1
帖 子:62
专家分:213
注 册:2015-4-4
得分:20 
回复 楼主 JackBrian
你的这个程序的 head  一直为null,然后你又去访问 head的元素,所以肯定会崩溃的哦
2015-04-15 10:46



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-444019-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.901895 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved