C语言,为什么从文件中读取的内容后面有很多乱码?谁能帮忙解决?
发布网友
发布时间:2022-04-29 02:10
我来回答
共1个回答
热心网友
时间:2022-04-15 08:26
你不能既读到a中,又读到file1中,只能读到其中一个变量中.而且char
a[5][10]不够,要增大到与conformation相同,即char
a[5][1024].下面修改为只读到file1中:
//char
a[5][10];
//fscanf(fp,"%s",&a[0]);
fscanf(fp,"%s",&file1.title);
//fscanf(fp,"%s",&a[1]);
fscanf(fp,"%s",&file1.content);
//fscanf(fp,"%s",&a[2]);
fscanf(fp,"%s",&file1.time);
//fscanf(fp,"%s",&a[3]);
fscanf(fp,"%s",&file1.author);
fclose(fp);
//printf("%s",a[0]);
printf("%s\n",file1.title);//加'\n'
printf("%s",file1.title);
//printf("%s",a[1]);
printf("%s\n",file1.content);//printf("%s",file1.content);
//printf("%s",a[2]);
printf("%s\n",file1.time);//printf("%s",file1.time);
//printf("%s",a[3]);
printf("%s\n",file1.author);//printf("%s",file1.author);