fwrite和fread出现乱码
#include <stdio.h> typedef struct z1
{
int num;
char name[12];
float score;
}data;
int main(void)
{
FILE *fp,*p;
data *info;
if ((fp=fopen("d:\\a.txt", "wb"))==NULL)
{
printf( "Cannot open input file.\n");
exit(1);
}
printf("\n input: \n ");
info=(data *)malloc(sizeof(data));
scanf("%d %s %f",&info->num,info->name,&info->score);
printf("%d %s %f\n",info->num,info->name,info->score);
fwrite(info,sizeof(data),1,fp);
rewind(fp);
fread(p,sizeof(data),1,fp);
fprintf(fp,p);
}