我要创建一个链表3个元素,但是编译不过用的turboC2.01,我的程序是从书上抄来的 详细看下面: 5
#include<stdio.h>voidcreate2();typedefstructlist_node*list_pointer;typedefstructlist_...
#include<stdio.h>
void create2();
typedef struct list_node *list_pointer;
typedef struct list_node
{
int data;
list_pointer link;
};
list_pointer ptr = NULL;
void main()
{
list_pointer p0;
create2();
/*printf("%d",p1->data);*/
}
void create2()
{
list_pointer p1,p2,p3;
p1 = (list_pointer)malloc(sizeof(list_node));
p2 = (list_pointer)malloc(sizeof(list_node));
p3 = (list_pointer)malloc(sizeof(list_node));
p1->link = p2;
p1->data = 1;
p2->link = p3;
p2->data = 2;
p3->link = NULL;
p3->data = 3;
/*return p1;*/
}
ERROR D:\TC\CODE\1.C 34:Undefined structure 'list_node' in function create2
求高人解答,谢谢 展开
void create2();
typedef struct list_node *list_pointer;
typedef struct list_node
{
int data;
list_pointer link;
};
list_pointer ptr = NULL;
void main()
{
list_pointer p0;
create2();
/*printf("%d",p1->data);*/
}
void create2()
{
list_pointer p1,p2,p3;
p1 = (list_pointer)malloc(sizeof(list_node));
p2 = (list_pointer)malloc(sizeof(list_node));
p3 = (list_pointer)malloc(sizeof(list_node));
p1->link = p2;
p1->data = 1;
p2->link = p3;
p2->data = 2;
p3->link = NULL;
p3->data = 3;
/*return p1;*/
}
ERROR D:\TC\CODE\1.C 34:Undefined structure 'list_node' in function create2
求高人解答,谢谢 展开
展开全部
#include<stdio.h>
void create2();
typedef struct list_node *list_pointer;
typedef struct list_node
{
int data;
list_pointer link;
};
list_pointer ptr = NULL;
void main()
{
list_pointer p0;
create2(p0);
/*printf("%d",p1->data);*/
}
void create2(list_pointer p)
{
list_pointer p1,p2,p3;
p1 = p;
p2 = (list_pointer)malloc(sizeof(list_node));
p3 = (list_pointer)malloc(sizeof(list_node));
p1->link = p2;
p1->data = 1;
p2->link = p3;
p2->data = 2;
p3->link = NULL;
p3->data = 3;
/*return p1;*/
}
子函数create2创建了内存空间但并不返回使用,所以编译器就报错,上面是对你的程序稍作修改,你再编译看看
void create2();
typedef struct list_node *list_pointer;
typedef struct list_node
{
int data;
list_pointer link;
};
list_pointer ptr = NULL;
void main()
{
list_pointer p0;
create2(p0);
/*printf("%d",p1->data);*/
}
void create2(list_pointer p)
{
list_pointer p1,p2,p3;
p1 = p;
p2 = (list_pointer)malloc(sizeof(list_node));
p3 = (list_pointer)malloc(sizeof(list_node));
p1->link = p2;
p1->data = 1;
p2->link = p3;
p2->data = 2;
p3->link = NULL;
p3->data = 3;
/*return p1;*/
}
子函数create2创建了内存空间但并不返回使用,所以编译器就报错,上面是对你的程序稍作修改,你再编译看看
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询