C语言链表问题无情的报错了
本帖最后由 Benjaminzhou93 于 2013-10-10 22:30:24 编辑 typedef struct
{
int n;
struct list* next;
}list;
void main()
{
list lst, a, b, c, *d;
lst.next = &a;
a.next = &b;
b.next = &c;
d = lst.next->next;//13行
}
E:\Windows工作区\test3.c(10) : warning C4133: '=' : incompatible types - from 'struct list *' to 'struct list *'
E:\Windows工作区\test3.c(11) : warning C4133: '=' : incompatible types - from 'struct list *' to 'struct list *'
E:\Windows工作区\test3.c(12) : warning C4133: '=' : incompatible types - from 'struct list *' to 'struct list *'
E:\Windows工作区\test3.c(13) : error C2037: left of 'next' specifies undefined struct/union 'list'
执行 cl.exe 时出错.
[解决办法]
本帖最后由 max_min_ 于 2013-10-10 22:32:28 编辑
//定义改成吧
typedef struct _list_tags
{
int n;
struct _list_tags* next;
}list;
typedef struct list
{
int n;
struct list* next;
}list;
#include <stdio.h>
typedef struct list
{
int n;
struct list *next;
} list;
int main()
{
list lst, a, b, c, *d;
lst.next = &a;
a.next = &b;
b.next = &c;
d = lst.next->next;
return 0;
}