ITPub博客

首页 > > > 请为什么文本文件里只有姓名是正常的,而其他显示的是乱码?

请为什么文本文件里只有姓名是正常的,而其他显示的是乱码?

作者:mex 时间:2019-11-18 10:22:42 0 删除 编辑

include<stdio.h>

include<stdlib.h>

struct student

{

char name[20];

int number[20];

int age;

}stu[6],stu[6]={

{"p",136,19},

{"ni",295,19},

{"kui",210,20},

{"gn",204,19},

{"wangwei",209,19},

{"liyig",214,19}

};

void main(){

FILE*fp;inti;

if( (fp=fopen("E:\ws.txt","wb"))==NULL)

{ printf("cannot open the file!"); getchar();exit(1);

for(i=0;i<6;i++)

{

scanf("%s %d %d",stu[i].name,stu[i].number,stu[i].age);

}

}

fwrite((char)stu,sizeof(struct student),6,fp);

fclose(fp);

if((fp=fopen("ws.txt","rb"))==NULL);

{

exit(0);

}

fread((char

)stu,sizeof(struct student),6,fp);

for(i=0;i<6;i++)printf("%s %d %s",stu[i].name,stu[i].number,stu[i].age);fclose(fp);

}*/

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/3932/viewspace-3119845/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-07-09

  • 博文量
    193
  • 访问量
    1886