| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1033 人关注过本帖
标题:C语言链表的结构指针定义报错非法,求指点。
只看楼主 加入收藏
juliawen
Rank: 1
等 级:新手上路
帖 子:27
专家分:0
注 册:2017-11-23
结帖率:0
收藏
已结贴  问题点数:20 回复次数: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-07 23:04
LiGoudan
Rank: 3Rank: 3
等 级:论坛游侠
威 望:2
帖 子:20
专家分:148
注 册:2018-2-28
收藏
得分:20 
list*headPtr,lastPtr,currentPtr;//指针定义错误,list *headPtr, *lastPtr, *currentPtr;

建议养成良好的代码编写习惯!
2018-03-07 23:54
快速回复:C语言链表的结构指针定义报错非法,求指点。
数据加载中...
 
   



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

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