C语言通讯录代码,为什么重新打开程序不能显示存储的数据 100
intloadfile(){intNO=0;FILE*fp;if((fp=fopen("contact.txt","rb"))==0){printf("\n\n\n\n\...
int loadfile()
{
int NO=0;
FILE *fp;
if((fp=fopen("contact.txt","rb"))==0)
{
printf("\n\n\n\n\n\t\t\t~~~~(>_<)~~~~电话簿文件不存在");
if ((fp=fopen("contact.txt","wb"))==0)
{
printf("\n\t\t\t\t%>_<%建立失败");
exit(0);
}
else
{
printf("\n\t\t\t ^_^电话簿已建立");
printf("\n\t\t\t 按任意键进入主菜单");
getch();
return(NO);
}
exit(0);
}
fseek(fp,0,2);
if (ftell(fp)>0)
{
rewind(fp);
for (NO=0;!feof(fp) && fread(&contact[NO],sizeof(struct record),1,fp);NO++);
printf("\n\n\n\n\t\t\t\t:)文件导入成功");
printf("\n\t\t\t 按任意键进入主菜单");
getch();
return(NO);
}
printf("\n\n\n\n\t\t\t :)文件导入成功");
printf("\n\t\t\t+_+电话簿文件中无任何纪录");
printf("\n\t\t\t 按任意键返回主菜单");
getch();
return(NO);
fclose(fp);
} 展开
{
int NO=0;
FILE *fp;
if((fp=fopen("contact.txt","rb"))==0)
{
printf("\n\n\n\n\n\t\t\t~~~~(>_<)~~~~电话簿文件不存在");
if ((fp=fopen("contact.txt","wb"))==0)
{
printf("\n\t\t\t\t%>_<%建立失败");
exit(0);
}
else
{
printf("\n\t\t\t ^_^电话簿已建立");
printf("\n\t\t\t 按任意键进入主菜单");
getch();
return(NO);
}
exit(0);
}
fseek(fp,0,2);
if (ftell(fp)>0)
{
rewind(fp);
for (NO=0;!feof(fp) && fread(&contact[NO],sizeof(struct record),1,fp);NO++);
printf("\n\n\n\n\t\t\t\t:)文件导入成功");
printf("\n\t\t\t 按任意键进入主菜单");
getch();
return(NO);
}
printf("\n\n\n\n\t\t\t :)文件导入成功");
printf("\n\t\t\t+_+电话簿文件中无任何纪录");
printf("\n\t\t\t 按任意键返回主菜单");
getch();
return(NO);
fclose(fp);
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询