| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 323 人关注过本帖
标题:各位大神,请问我的动态链表程序怎么运行崩溃
只看楼主 加入收藏
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
快速回复:各位大神,请问我的动态链表程序怎么运行崩溃
数据加载中...
 
   



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

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