文件写如的疑问

Tangxiang Tangxiang 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
当写如时候,字符可以正常显示,但是数字却是乱码,
请教哈
是不是和写入方式有关呢?(wb)
代码如下:
#include<stdio.h>
#include<stdlib.h>

#define WLM printf("*******End of the program!******")
#define SIZE 4
struct student_type
{
char name[10];
int num;
int age;
char addr[20];
} stud[SIZE];
//define the struct

void save(char *pfn)
{
FILE *fp;
int i;
char *pf=pfn;

if((fp=fopen(pf,"wb"))==NULL)
{
printf("Can't open the file!\n");
return; //exit(0);
}

for(i=0;i<SIZE;i++)
{
if(fwrite(&stud[i],sizeof(struct student_type),1,fp)!=1)
{
printf("Write Error!\n");
}
}
fclose(fp);//Can't forget!

}//End of The Save()

main()
{
int i;
char filename[20];
char *pfn=filename;

printf("Please input the file name:");
scanf("%s",filename);

printf("Please input the Students' contents:\n");

for(i=0;i<SIZE;i++)
{
scanf("%s%d%d%s",stud[i].name,&stud[i].num,&stud[i].age,stud[i].addr);

save(pfn);
}

WLM;
system("pause");
}
...全文
评论 9
收藏 已收藏
分享
返回顶部
Tangxiang
C语言 70,039 成员 243,237 内容