标题:链表程序找不出错误
取消只看楼主
robo
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2004-8-11
 问题点数:0 回复次数:1 
链表程序找不出错误

# include <stdio.h> struct list { int num; list* next; 1 }; list* head=NULL; 2 list* create() 3 { list *p,*q; p=(struct list*)malloc(sizeof(struct list)); printf("input a integer:\n"); scanf("%d",&(p->num)); q=p; while(p->num!=0) { if(head==NULL) head=p; else q->next=p; q=p; p=(struct list*)malloc(sizeof(struct list)); scanf("%d",&(p->num)); } q->next=NULL; free(p); return(head); } void print(list* head) { while(head) { printf("\n%d",head->num); head=head->next; } } void main() { print(create()); }

程序创建一个链表,并把其中数据打印出来,编译后有三个错误: 1处的错误为Declaration missing ; . 2处的错误为Declaration syntax error . 3处的错误为Declaration syntax error . 请高手帮忙指正,谢了

搜索更多相关主题的帖子: 链表 
2004-08-16 16:51
robo
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2004-8-11
得分:0 

刚才试了一下,确实如两位高手所言,在list前加struct或者干脆直接先用typedef定义struct list 为 list 都可以改正错误,谢谢高手指点

2004-08-16 18:43



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




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

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