...fscanf,读取TXT型文档,文字全出现了但有很多乱码,求大神帮忙啊...答:在fscanf(fp,"%d,%s,%d,%s,%s,%d\n",&q->number,q->name,&q->salary,q->sex,q->department,&q->time);中,遇到第1个%s时,将读取30个字节的name[30],如果文本存储的name长度不足30,将后面的字符作为name使用看待,使得后面的读取越界没有意义,出现随机乱码。
C语言用 fscanf 输入文件显示 乱码答:int age;};void main(){ struct worker wk = {0, '\0', 0};int n;FILE *in;if((in=fopen("file1.txt","r"))==NULL){ printf("The file %s can not be opened.\n","file1.txt");return;} fscanf(in,"%d %s %d\n",&wk.number,wk.name,&wk.age);printf("%d,%s,%d"...