红联Linux门户
Linux帮助

linux链表问题

发布时间:2012-03-12 21:13:12来源:红联作者:与我无关
这个代码,是LINUX链表最基本操作,虽编译成功,可以运行,不过GCC给出警告:函数返回局部变量地址。该怎么处理呀,求大家帮助

#include
#include "list.h"
#include


typedef struct list
{
int data;
struct list_head list;
} USER,*User;


struct list_head *Creat();
struct list_head Show(struct list_head *t);


main()
{
struct list_head *pt = NULL;
pt = Creat();
Show(pt);
}


struct list_head *Creat()
{
LIST_HEAD(t);
User H = NULL;
int ch = 1;

while(0 != ch)
{
printf("input a integer number(0 to stop):");
scanf("%d",&ch);
if(0 == ch)
{
break;
}
H = (User)malloc(sizeof(USER));

H->data = ch;
list_add_tail(&(H->list),&t);
}
return &t;
}


struct list_head Show(struct list_head *t)
{
User p = NULL;
struct list_head *pno = NULL;
list_for_each(pno,t)
{
p = list_entry(pno,USER,list);
printf("%d\n",p->data);
}
}
文章评论

共有 1 条评论

  1. 与我无关 于 2012-03-12 21:40:59发表:

    加static