c语言链表创建问题,溢出问题!

[复制链接]
查看11 | 回复1 | 2011-5-21 11:48:47 | 显示全部楼层 |阅读模式
我写了一个创建链表的函数,找到溢出的地方了,但不知道为啥溢出,麻烦懂的人帮忙看下,谢谢了!
代码如下:
#includestdio.h
#includemalloc.h
structstudent
{
        charnum;
        intscore;
        structstudent*next;
};
structlist
{
        structstudent*head;
        structstudent*rail;
};
voidcreat(structlist*a)
{
        structstudent*pnew;
        a-rail=a-head;
        pnew=(structstudent*)malloc(sizeof(structstudent));
        printf(\"请输入学生学号成绩(学号为0结束输入):\\n\");
        scanf(\"%c%d\",num,score);
        while(pnew-num!=\'0\')
        {
        a-rail-next=pnew;//在这边产生溢出了!为啥??
                a-rail=pnew;
                pnew=(structstudent*)malloc(sizeof(structstudent));
                scanf(\"%c%d\",num,score);
        }
        a-rail-next=NULL;
}
回复

使用道具 举报

千问 | 2011-5-21 11:48:47 | 显示全部楼层
a-rail还没有分配空间啊
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行