为什么把结构体写入文本文件,打开文件啥都没有
void EngineerInfomationSave(ENG *head)
{
FILE *fp;
ENG *cur;
fp=fopen( "engineer.txt ", "w ");
if(fp==NULL)
{
printf( "不能打开文件,按任意键退出 ");
fflush(stdin);
getch();
exit(-1);
}
for(cur=head-> next;cur-> next==NULL;cur=cur-> next)
{
if(fwrite(cur,sizeof(struct EngineerStruct),1,fp)!=1)
{
printf( "文件写入错误,按任意键退出 ");
fclose(fp);
fflush(stdin);
getch();
exit(-1);
}
}
fclose(fp);
printf( "数据成功保存,按任意键返回 ");
fflush(stdin);
getch();
}
执行结构就是 数据成功保存,按任意键返回 打开文件什么都没有(结构体内容已经输入)
[解决办法]
for(cur=head-> next;cur-> next==NULL;cur=cur-> next)
cur-> next==NULL?
for循环是不是有问题?如果head-> next-> next!=NULL则直接退出循环了。
另外按二进制写应该是wb。