读取文件输出乱码问题
已经写入了一个student.dat文件,下面代码就是读取输出,但是输出乱码了。写入文件为
Student stus[3]={{"teacher","tea123","0"},{"student","stu123","0"},{"fdy","fdy123","1"}};
程序代码:
#include <stdio.h>
#include <stdlib.h>
#include"conio.h"
#include"string.h"
#include"windows.h"
typedef
struct{
char name[20];
char ps[10];
char power[10];
}Student;
int main(){
printf("数组temp的内容为:\n");
int i;
Student show[3];
int size=sizeof(Student);
FILE *fp=fopen("student.dat","rb");
if(fp==NULL){
printf("文件%s打不开\n","student");
}
else if(fp!=NULL){
for(i=0;i<3;i++){
int count=fread(show,size,1,fp);
if(count==1){
show[i]=*show;
}
}
fclose(fp);
}
printf("%s%s%s\n",show[1].name,show[2].name,show[3].name);
}[此贴子已经被作者于2016-12-25 19:12编辑过]









