关于通讯录的创建问题
我有一道作业题,题目是这样的:通讯录管理系统要求:建立通讯录,实现通讯者的插入、删除、查询、以及通讯录表的输出等。
以下是我写的程序,可是运行的时候在创建列表的部分老是跳不出来,跪请各位高手们不吝赐教
#include <stdio.h>
#include <string.h>
#include <malloc.h>
#define NULL 0
#define LEN sizeof(struct tongxue)
struct tongxue
{ char xingming[20];
long dianhua[11];
char dizhi[50];
struct tongxue *next;
};
int n;
struct tongxue *creat(void) /*定义函数,返回一个指向链表头的指针*/
{struct tongxue *head;
struct tongxue *p1,*p2;
n=0;
p1=p2=(struct tongxue *) malloc(LEN);
scanf("%s,%ld,%s",p1->xingming,&p1->dianhua,p1->dizhi);
head=NULL;
while(p1->xingming!=0)
{n=n+1;
if(n==1)head=p1;
else p2->next=p1;
p2=p1;
p1=(struct tongxue *)malloc(LEN);
scanf("%s,%ld,%s",&p1->xingming,&p1->dianhua,p1->dizhi);
}
p2->next=NULL;
return(head);
}
/*通讯录链表生成函数*/
struct tongxue search(char cha_mingzi[20])
{struct tongxue *p1,*p2,*head;
head=creat();
p1=p2=head;
scanf("%s",cha_mingzi);
do
{if(strcmp(cha_mingzi,p1->xingming)==0)
printf("%s,%ld,%s",p1->xingming,&p1->dianhua,p1->dizhi);
else p2=p1,p1=p1->next;
}while(p1->xingming!=0);
printf("查无此人");
struct tongxue a;
return(a); }
/*通讯录成员查询函数*/
void print(struct tongxue *head)
{struct tongxue *p;
printf("\n现在,这%d个人的通讯录为:\n",n);
p=head;
if(head!=NULL)
do
{printf("%s,%ld,%s",p->xingming,p->dianhua,p->dizhi);
p=p->next;
}while(p!=NULL);
}
//通讯录链表输出函数
struct tongxue *del(struct tongxue *head,char del_mingzi[50])
{struct tongxue *p1,*p2;
if(head=NULL) {printf("\n空链表!\n");goto end;}
p1=head;
while(strcmp(del_mingzi,p1->xingming)!=0&&p1->next!=NULL) /*p1指向的不是要找的结点并且后面还有结点*/
{p2=p1;p1=p1->next;} /*p1后移一个结点*/
if(strcmp(del_mingzi,p1->xingming)==0)
{if(p1==head)head=p1->next; /*若p1是首结点,把第二个结点地址赋予head*/
else p2->next=p1->next; /*否则将下一结点的地址赋予前一结点地址*/
printf("delete:%s\n",del_mingzi);
n=n-1;
}
else printf("没有找到%s\n",del_mingzi); /*找不到该结点*/
end:
return(head);
}
/*通讯录成员删除函数*/
struct tongxue *insert(struct tongxue *head,struct tongxue *p0,char *x) /*p0为插入的结点,x为插入点*/
{struct tongxue *p,*q;
if(head==NULL)
{head=p0;
p0->next=NULL; /*空表时,直接插入结点*/
}
else
{p=head;
while(strcmp(x,p->xingming)!=0&&p->next!=NULL)
{q=p;p=q->next;}
if(strcmp(x,p->xingming)==0)
{if(p==head) head=p0; /*在表头插入结点*/
else
q->next=p0;p0->next=p;/*在表中间插入结点*/
}
else
{p->next=p0;p0->next=NULL;} /*在表尾插入结点*/
}
return(head);
}
/* 通讯录成员插入函数*/
void main()
{struct tongxue *head,*tx;char name[20];
char xingming[20],dizhi[50];long dianhua[11];
char del_mingzi[20],cha_mingzi[20];
printf("输入通讯录\n");
head=creat();
print(head);
printf("\n输入要查询的名字:");
scanf("%s",cha_mingzi);
search(cha_mingzi);
printf("\n请输入要删除的名字:");
scanf("%s",del_mingzi);
while(del_mingzi!=0)
{head=del(head,del_mingzi);
print(head);
printf("\n请输入要删除的名字:");
printf("%s",del_mingzi);
}
printf("\n请输入要插入的成员的信息:");
tx=(struct tongxue *)malloc(LEN);
scanf("%s,%ld,%s",xingming,&dianhua,dizhi);
printf("\n请输入插入点:");
scanf("%s",name);
while("tx->xingming!=0")
{head=insert(head,tx,name);
print(head);
printf("\n请输入要插入的成员的信息:");
tx=(struct tongxue *)malloc(LEN);
scanf("%s,%ld,%s",xingming,&dianhua,dizhi);
printf("\n请输入插入点:");
scanf("%s",name);
}
}