我的通讯录为什么删除不掉联系人,望大神指点
/*个人通讯录*/#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct dataWab{
char name[8];
char postcode[16];
char mobile[16];
char address[16];
struct dataWab *nextPtr;
}; /*自引用结构,用作通讯录的数据结构*/
typedef struct dataWab DATAWAB;
typedef DATAWAB *DATAWABPTR;
void insertWab(DATAWABPTR*,char[],char[],char[],char[]); /*插入函数*/
void menuWab(void); /*菜单函数*/
void printWab(DATAWABPTR); /*打印所有记录函数*/
void seekWab(DATAWABPTR,char[]); /*查找函数*/
void deleteWab(DATAWABPTR,char[]); /*删除函数*/
void modifyWab(DATAWABPTR,char[]); /*修改函数*/
int test(DATAWABPTR); /*测试函数,测试通讯录内是否有记录*/
void printone(DATAWABPTR); /*打印单条记录函数*/
int controlWab(void); /*程序分支控制函数*/
int main()
{
DATAWABPTR startPtr=NULL;
DATAWABPTR tempPtr;
FILE *fileWab;
char menu; /*菜单操作控制变量*/
char insert; /*插入确认控制变量*/
char modifyName[8]; /*查找时的临时姓名存储*/
char deleteName[8]; /*删除时的临时姓名存储*/
char tempName[8]; /*临时姓名存储*/
char tempPostcode[16]; /*临时邮编存储*/
char tempMobile[16]; /*临时手机存储*/
char tempAddress[16]; /*临时地址存储*/
char seekName[8]; /*查找时的临时姓名存储*/
puts("\n\n\t\t欢迎使用通讯录管理系统\n");
menuWab();
menu=getch();
while(menu!='6'){
switch(menu){
case '1':
printWab(startPtr);
getch();
break;
case '2':
while(controlWab()){
printf("\n查找姓名:\n#>");
scanf("%s",seekName);
seekWab(startPtr,seekName);
}
break;
case '3':
while(controlWab()){
puts("\n录入个人信息\n");
printf("姓名:");
scanf("%s",tempName);
printf("\n邮编:");
scanf("%s",tempPostcode);
printf("\n手机:");
scanf("%s",tempMobile);
printf("\n地址:");
scanf("%s",tempAddress);
printf("录入正确请按 1 \n#>");
insert=getch();
if(insert=='1')
insertWab(&startPtr,tempName,tempPostcode,tempMobile,
tempAddress);
}
break;
case '4':
while(controlWab()){
printf("\n删除姓名\n#>");
scanf("%s",deleteName);
deleteWab(startPtr,deleteName);
}
break;
case '5':
while(controlWab()){
printf("\n修改姓名\n#>");
scanf("%s",modifyName);
modifyWab(startPtr,modifyName);
}
break;
default:
puts("\n\n输入选项错误,请重新输入\n");
break;
}
menuWab();
menu=getch();
}
if((fileWab=fopen("wab.dat","wb"))==NULL)
return 0;
while(startPtr!=NULL){
fwrite(startPtr,sizeof(DATAWAB),1,fileWab);
startPtr=startPtr->nextPtr;
}
puts("\n\n\t\t感谢使用通讯录管理系统,再见!\n");
}
void menuWab(void) /*菜单函数*/
{
puts("**********************通讯录管理**************************");
puts("**********************************************************");
puts("**\t[-1-]所有记录\t\t[-2-]查找记录\t\t**");
puts("**\t[-3-]增加记录\t\t[-4-]删除记录\t\t**");
puts("**\t[-5-]修改记录\t\t[-6-]退出系统\t\t**");
puts("**********************************************************");
puts("**********************************************************");
puts("\n请选择 1-6");
printf("#>");
}
void insertWab(DATAWABPTR *tempPtr,char temp2Name[],char temp2Postcode[],
char temp2Mobile[],char temp2Address[])
/*插入函数*/
{
DATAWABPTR newPtr;
newPtr=(DATAWABPTR)malloc(sizeof(DATAWAB));
strcpy(newPtr->name,temp2Name);
strcpy(newPtr->postcode,temp2Postcode);
strcpy(newPtr->mobile,temp2Mobile);
strcpy(newPtr->address,temp2Address);
newPtr->nextPtr=*tempPtr;
*tempPtr=newPtr;
}
void printWab(DATAWABPTR printPtr) /*打印函数*/
{
if(!(test(printPtr))){
printf("\n%8s%16s%16s%16s%16s\n","姓名","邮编","手机","住址");
while(printPtr!=NULL){
printf("%8s%16s%16s%16s%\n",printPtr->name,printPtr->postcode,
printPtr->mobile,printPtr->address);
printPtr=printPtr->nextPtr;
}
}
}
void seekWab(DATAWABPTR seekPtr,char tempName[])
/*查找函数*/
{
if(!(test(seekPtr))){
while(seekPtr!=NULL){
if(!(strcmp(tempName,seekPtr->name))){
printone(seekPtr);
seekPtr=seekPtr->nextPtr;
}
else
seekPtr=seekPtr->nextPtr;
}
}
}
void deleteWab(DATAWABPTR deletePtr,char deleteName[])
/*删除函数*/
{
DATAWABPTR tempPtr,forePtr;
forePtr=deletePtr;
tempPtr=deletePtr->nextPtr;
while(tempPtr!=NULL){
if(!(strcmp(tempPtr->name,deleteName))){
forePtr->nextPtr=tempPtr->nextPtr;
free(tempPtr);
break;
}
else{
forePtr=tempPtr;
tempPtr=tempPtr->nextPtr;
}
}
}
void modifyWab(DATAWABPTR modifyPtr,char modifyName[])
/*修改函数*/
{
if(!(test(modifyPtr))){
while(modifyPtr!=NULL){
if(!(strcmp(modifyName,modifyPtr->name))){
printf("请输入新姓名:");
scanf("%s",modifyPtr->name);
printf("\n请输入新邮编:");
scanf("%s",modifyPtr->postcode);
printf("\n请输入新手机:");
scanf("%s",modifyPtr->mobile);
printf("\n请输入新地址:");
scanf("%s",modifyPtr->address);
break;
}
else
modifyPtr=modifyPtr->nextPtr;
}
}
}
int test(DATAWABPTR testPtr)
{
if(testPtr==NULL)
puts("通讯录内没有任何记录");
else
return 0;
return 1;
}
void printone(DATAWABPTR printone)
{
printf("\n%8s%16s%16s%16s%\n","姓名","邮编","手机","住址");
printf("%8s",printone->name);
printf("%16s",printone->postcode);
printf("%16s",printone->mobile);
printf("%16s",printone->address);
}
int controlWab(void)
{
puts("继续执行请按 1");
if(getch()=='1')
return 1;
return 0;
}