通讯录的修改函数,错误在那里?
xg() /*修改函数*/{
struct xx XX;
FILE *fp1,*fp2;
int flag;
char ch[15];
int a;
if((fp1=fopen("xinxi.txt","rb"))==NULL)
{
printf("错误!不能打开记录文件(xinxi.txt)!");
getch();
main();
}
if((fp2=fopen("temp.txt","wb"))==NULL)
{
printf("错误!不能打开记录文件(temp.txt)!");
getch();
main();
}
printf("要修改谁(输入名字):");
gets(ch);
getchar();
flag=0;
while(fread(&XX,sizeof(XX),1,fp1)==1)
{
if(strcmp(ch,XX.xingming)==0)
{
printf("\n姓名:%s\n",XX.xingming);
printf("性别 :%s\n",XX.xingbie);
printf("电话 :%s\n",XX.dianhua);
printf("QQ :%s\n",XX.qq);
printf("E-M :%s",XX.email);
printf("\n\n\n按任意键,输入新记录!\n");
getch();
printf("姓名:");
gets(XX.xingming);
printf("性别:");
gets(XX.xingbie);
printf("电话:");
gets(XX.dianhua);
printf("QQ:");
gets(XX.qq);
printf("E-mail:");
gets(XX.email);
flag=1;
}
fwrite(&XX,sizeof(XX),1,fp2);
}
fclose(fp1);
fclose(fp2);
if(flag==1)
{
printf("Modify sucess!\n");
remove("xinxi.txt");
rename("temp.txt","xinxi.txt");
}
else
printf("找不到这个记录!\n");
getch();
printf("1.继续||2.返回||3.退出-->[ ]\b\b");
scanf("%d",&a);
if(a==1)
{
system("cls");
xg();
}
else if(a==2)
{
main();
}
else if(a==3)
{
exit(0);
}
}