#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct node
{
char name[20];
char tel[9];
struct node *next;
};
struct node *create()
{
struct node *head,*p,*q;
char name[20];
head=NULL;
printf("name:");
gets(name);
while (strlen(name)!=0)
{
p=(struct node *)malloc(sizeof(struct node));//开辟新结点
if(p==NULL)
{
printf("allocation failure\n");
exit(0);
}
strcpy(p->name,name);
printf("tel:");
gets(p->tel);
p->next=NULL;
if(head==NULL)
head=p;
else
q->next=p;
q=p;//令p指向新的结点
printf("name:");
gets(name);
}
return head;
}
void main()
{
struct node *head;
head=create();
printf("%d\n",head);
}