c语言 用fwrite写入txt的文件,为什么是一堆乱码呢 ,下面是我的程序

void addRecord(void) { int i; char str[10]; int val=0,unval=0; char s[3]; FILE *fp; if(numApps==0) printf("原来没有记录,现在建立新的记录\n"); else printf("下面在当前文件添加新的记录\n"); while(1) { printf("确定要添加一组新设备信息?(Y/N)"); gets(s); if(s[0]=='n'||s[0]=='N') //不再添加信息 break; if(numApps>=Record_arraySize) //数组空间不足,需要重新申请空间 { records=realloc(records,(Record_arraySize+INCR_SIZE)*sizeof(AppInfo)); if(records==NULL) { printf("memory failed!"); exit(-1); } Record_arraySize=Record_arraySize+INCR_SIZE; } printf("\n\t请输入设备仪器的信息\n"); printf("\t编号:"); gets(records[numApps].number); printf("\t名称:"); gets(records[numApps].name); printf("\t单价:"); gets(str); records[numApps].price=(float)atof(str); printf("\t购进日期:"); gets(records[numApps].inDate); printf("\t生产厂家: "); gets(records[numApps].producter); printf("\t购进数量: "); gets(str); records[numApps].count=(int)atoi(str); while(Usability_arraySize { Usability_arraySize+=INCR_SIZE; } printf("\t仪器设备的可用性(Y)与不可用性(N):\n"); for(i=1;i<=records[numApps].count;i++) { printf("\t第%d台的可用性:",i); gets(s); records[numApps].usability[i-1]=s[0]; } numApps++; printf("\n是否继续添加新的设备信息?(Y/N)"); gets(s); if(s[0]=='n'||s[0]=='N') break; } printf("现在一共有%d条记录\n",numApps); printf("存文件……\n"); fp=fopen("app_info.txt","w"); for(i=0;i { fwrite(&records[i],sizeof(AppInfo),1,fp); } fclose(fp); printf("%d条记录已经存入文件!\n",numApps); } 下面是我保存文件出现的对话框

这个函数以二进制形式对文件进行操作
按数据定义结构的写入保持数据结构的长度,对于数值类型,再用文本方式打开时表现为
乱码。例如float
a=12345.67,写入文件后为4个字节,打开后不是文本表示的8个字节。
温馨提示:答案为网友推荐,仅供参考