本程序在vi编辑器里运行通过!
#include <stdio.h>
#include <string.h>
typedef struct mylist
{
char content[8];
struct mylist * next;
}List;
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->next;
while(tmp!=NULL)
{
printf("%s",tmp->content);
tmp=tmp->next;
}
return 1;
}
int main()
{
List * head = newList("abcdefg");
List * element;
int i=0;
for(;i<5;i++)
{
element = newList("1234567/n");
element = newList("1234567");
addtailer(head,element);
}
search(head);
system("pause");
}