您的位置:首页 > 编程语言 > C语言/C++

请大家看一下一个c语言中的链表问题,下面的代码是有错误的!!请大家说出错误的原因,以及修改的方法!!!

2008-11-20 16:31 597 查看
请大家看一下一个c语言中的链表问题,下面的代码是有错误的!!请大家说出错误的原因,以及修改的方法!!!

#include <stdio.h>
#include <string.h>

typedef struct mylist
{
char content[8];
struct mylist * next;
}List;
List * dig();
List * newList(char * content)
{
if(strlen(content)!=7)
return NULL;
List * tmp =(List *) malloc(sizeof(List));
strcpy(tmp->content,content);
tmp->next=0;
return tmp;
}

int addtailer(List* head,List * n)
{
while((head->next) != 0)
{
head=head->next;
}
head->next = n;
}
int search(List * head)
{
List * tmp=head;
while(tmp!=NULL)
{
printf("%s",tmp->content);
tmp=tmp->next;
}
return 1;
}

int main()
{
List * head = dig();
search(head);
}
List * dig()
{
List * head = newList("abcdefg");
List * element;
int i=0;
List list;
strcpy(list.content,"ererere");
for(;i<5;i++)
{
element = newList("1234567");
addtailer(head,element);
}
addtailer(head,&list);
return head;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐