通讯录问题执行到一半停止工作帮忙看看什么问题?
程序代码:
#include<stdio.h> #include<stdlib.h> #include<string.h> int n=4; struct person { int number; char name[10]; char sex; int telephone; int QQ; int hometele; //家庭电话 char email; char address[30]; //通讯地址 struct { unsigned short year; unsigned short month; unsigned short day; } birthday; //出生日期 struct person*last; struct person*next; }; struct person*head=NULL; struct person*p; int k; void create(struct person*head) { int i=0; p=(person*)malloc(sizeof(struct person)); if(p=NULL) { printf("申请内存不成功!"); free(p); return ; } else { printf("\n\n======================================================================\n\n"); printf("\t\t请输入以下信息:"); for(i=1;i<n;i++) { printf("\n\t\t第%d位同学的姓名:",i); scanf("%s",&(p->name)); printf("\t\t第%d位同学的性别:",i); scanf("%s",&(p->sex)); printf("\t\t第%d位同学的电话号码:",i); scanf("%d",&(p->telephone)); printf("\t\t第%d位同学的QQ:",i); scanf("%d",&(p->QQ)); printf("\t\t第%d同学的家庭号码:",i); scanf("%d",&(p->hometele)); printf("\t\t第%d位同学的电子邮件:",i); scanf("%s",&(p->address)); printf("\t\t第%d位同学的出生日期:",i); scanf("%d/%d/%d",&(p->birthday.year),&(p->birthday.month),&(p->birthday.day)); p=p->next; } p->next=NULL; printf("\n\n==========================================="); printf("\n\n\t\t信息记录保存成功!"); return ; } } void print(struct person*head) { printf("\n\n\t\t%-9s%-9s%-9s%-9s%-9s%-9s%-9s%-9s%-9s\n","学号","姓名","性别","电话号码","QQ号码","家庭电话","电子邮件","通讯地址","出生日期"); if(p!=NULL) { printf("\t\t%d\t\t\t %-6s%-3s",p->number,p->name,p->sex); printf("\t\t%d\t\t\t%d\t\t\t%d",p->telephone,p->QQ,p->hometele); printf("%-9s%-9s",p->email,p->address); printf("\t\t%d/%d/%d\n",p->birthday.year,p->birthday.month,p->birthday.day); p=p->next; } else { printf("\n\n\t\t目前此通讯录无任何记录!按任意键返回主菜单···"); scanf("%",&k); return ; } } //查找信息 void seek(struct person*head) { char name[10]; if(p==NULL) { printf("\n\n\t\t此通讯录暂无任何信息!按任意键返回主菜单···"); scanf("%d",&k); } else { printf("\t\t请输入需查找的人名:"); scanf("%s",&name); while(p!=NULL) { if(strcmp(p->name,name)==0) { printf("\n\n\t\t%s的信息如下:",&name); printf("\n======================================================================================================="); printf("\n\n\t\t%-9s%-9s%-9s%-9s%-9s%-9s%-9s%-9s%-9s\n","学号","姓名","性别","电话号码","QQ号码","家庭电话","电子邮件","通讯地址","出生日期"); printf("\t\t%d\t\t\t %-6s%-3s",p->number,p->name,p->sex); printf("\t\t%d\t\t\t%d\t\t\t%d",p->telephone,p->QQ,p->hometele); printf("%-9s%-9s",p->email,p->address); printf("\t\t%d/%d/%d\n",p->birthday.year,p->birthday.month,p->birthday.day); printf("\t\t请按任意键返回主菜单····\n"); scanf("%d",&k); return ; } p=p->next; } printf("\n\n\t\t你所输入的姓名有误或不存在!请按任意键返回主菜单····"); scanf("%d",&k); return ; } } //添加信息 void add(struct person*head) { struct person*h; //追加的节点 struct person*f; //中间变量 h=(struct person*)malloc(sizeof(struct person)); if(p==NULL) //需创建链表 { p=h; p->next=NULL; head->next=p; } else //说明需找到链表结束位置 { f=p; while(f->next!=NULL) { f=f->next; } f->next=h; h->last=f; h->next=NULL; } printf("\t\t请输入学号:"); scanf("%d",h->number); printf("\t\t请输入姓名:"); gets(h->name); printf("\t\t请输入性别:"); scanf("%s",&(h->sex)); printf("\t\t请输入电话号码:"); scanf("%d",&(h->telephone)); printf("\t\t请输入QQ号:"); scanf("%d",&(h->QQ)); printf("\t\t请输入家庭电话:"); scanf("%d",&(h->hometele)); printf("\t\t请输入电子邮件:"); scanf("%s",&(h->email)); printf("\t\t请输入通讯地址:"); gets(h->address); printf("\t\t添加成功!按任意键返回主菜单···"); scanf("%d",&k); return ; } //删除信息 void dele(struct person*p) { char name[10]; char d; if(p==NULL) { printf("\n\n\t\t通讯录目前无任何信息,无法执行删除!按任意键返回主菜单···"); scanf("%d",&k); return ; } else { printf("请输入需删除信息的人名:"); scanf("%s",&name); if(strcmp(p->name,name)==0) { printf("\n\t\t你确定要删除%s的信息(y/n)?",p->name); d=getchar(); if(d=='N'||d=='n') { printf("\n\t\t你选择了取消删除,请按任意键返回主菜单···"); scanf("%d",&k); return ; } else //确认删除 { //重建链表关系 (p->last)->next=p->next; (p->next)->last=p->last; } free(p); printf("\n\t\t信息删除成功!按任意键返回主菜单···"); scanf("%d",&k); return ; } p=p->next; } } //修改信息 void modify(struct person*head) { char name[10]; int m; printf("\n\t\t请输入需修改信息的人名字:"); scanf("%s",&name); while(p!=NULL) { if(strcmp(p->name,name)==0) { printf("\n\n\t\t%-9s%-9s%-9s%-9s%-9s%-9s%-9s%-9s%-9s\n","学号","姓名","性别","电话号码","QQ号码","家庭电话","电子邮件","通讯地址","出生日期"); printf("\t\t%d\t\t\t %-6s%-3s",p->number,p->name,p->sex); printf("\t\t%d\t\t\t%d\t\t\t%d",p->telephone,p->QQ,p->hometele); printf("%-9s%-9s",p->email,p->address); printf("\t\t%d/%d/%d\n",p->birthday.year,p->birthday.month,p->birthday.day); printf("\n\n\t\t请选择需修改的信息项:"); printf("\n\t\ta----学号"); printf("\n\t\tb----性别"); printf("\n\t\tc----电话号码"); printf("\n\t\td----QQ号码"); printf("\n\t\te----家庭电话"); printf("\n\t\tf----电子邮件"); printf("\n\t\tg----通讯地址"); printf("\nt\\th----出生日期"); printf("\t\t请选择:"); m=getchar(); switch(m) { case 'a':printf("\n\t\t请输入新的学号:"); scanf("%d",&(p->number));break; case 'b':printf("\n\t\t请输入新的性别:"); scanf("%s",&(p->sex));break; case 'c':printf("\n\t\t请输入新的电话号码:"); scanf("%d",&(p->telephone));break; case 'd':printf("\n\t\t请输入新的QQ号码:"); scanf("%d",&(p->QQ));break; case 'e':printf("\n\t\t请输入新的家庭电话:"); scanf("%d",&(p->hometele));break; case 'f':printf("\n\t\t请输入新的电子邮件:"); scanf("%s",&(p->email));break; case 'g':printf("\n\t\t请输入新的通讯地址:"); scanf("%s",&(p->address));break; default :printf("\n\t\t选择错误,请重新选择:"); getchar(); } printf("\nt\t\t修改成功!请按任意键返回主菜单···"); scanf("%d",&k); return ; } p=p->next; } printf("\n\t\t你所输入的人名有误或不存在!按任意键返回主菜单···"); scanf("%d",&k); return ; } void main() { int k; printf("\n\n\t\t========================================"); printf("\n\n\t\t\t=***欢迎使用本通讯录管理系统***=\n\n\n"); printf("\t\t请选择:(1-7):\n"); printf("\t\t**********************************************\n"); printf("\t\t\t1.建立通讯录\n"); printf("\t\t\t2.浏览通讯录信息\n"); printf("\t\t\t3.查找通讯录信息\n"); printf("\t\t\t4.添加通讯录信息\n"); printf("\t\t\t5.删除通讯录信息\n"); printf("\t\t\t6.修改通讯录信息\n"); printf("\t\t\t7.退出系统\n"); printf("\n\t\t*********************************************\n"); printf("\n\t\t你的选择是:"); scanf("%d",&k); switch(k) { case 1:create(head);break; case 2:print(head);break; case 3:seek(head);break;; case 4:add(head);break; case 5:dele(head);break; case 6:modify(head);break; case 7:return; default:printf("\t\t选择错误!请重新选择:"); scanf("%d",&k); } return ; }为什么每次执行到这里都停止工作?是因为没有用到文件吗?帮忙看看什么问题?谢谢
[ 本帖最后由 cyuyan793445 于 2013-3-6 15:15 编辑 ]