下面是源代码,能解释下吗
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
struct node
{
char name[20];
char tel[9];
struct node *next;
};
struct node *create()
{
struct node *head;
struct node *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;
printf("name:");
gets(name);
}
return head;
}
void main()
{
struct node *head;
head=create();
}