| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1134 人关注过本帖
标题:C语言链表的结构指针定义报错非法,求指点。
取消只看楼主 加入收藏
juliawen
Rank: 1
等 级:新手上路
帖 子:27
专家分:0
注 册:2017-11-23
结帖率:0
收藏
 问题点数:0 回复次数:1 
C语言链表的结构指针定义报错非法,求指点。
#include<stdio.h>
#include<stdlib.h>
struct list{
 int data;
 struct list*nextPtr;
};//创建结构体。
//创建链表。
list *createList(void)
{
int num;
list*headPtr,lastPtr,currentPtr;
headPtr=NULL;
lastPtr=NULL;
currentPtr=NULL;
//存储数字,直到出现-1停止。
    scanf("%d",&num);
while(num!=-1)
{
    currentPtr=malloc(sizeof(struct list));
    if(currentPtr!=NULL)
    {
        (*currentPtr).data=num;
        if(headPtr==NULL){
            headPtr=currentPtr;
            lastPtr=currentPtr;
                }
        else{
            (*lastPtr).nextPtr=currentPtr;
            lastPtr=currentPtr;
                }
    }
scanf("%d",&num);   
}   

(*lastPtr).nextPtr=NULL;
return headPtr;        
}

以上是代码
报错显示我定义的list*headPtr,lastPtr,currentPtr是无效的?????为什么?
搜索更多相关主题的帖子: 链表 报错 list num NULL 
2018-03-08 13:45
juliawen
Rank: 1
等 级:新手上路
帖 子:27
专家分:0
注 册:2017-11-23
收藏
得分:0 
回复 2楼 lanke711
感谢您不吝赐教
2018-03-13 19:59
快速回复:C语言链表的结构指针定义报错非法,求指点。
数据加载中...
 
   



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

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