C语言函数调用问题! 输出是一堆乱码!不复杂!大侠进!!

来源:百度知道 编辑:UC知道 时间:2024/06/08 14:37:51
#include<string.h>
#include<stdio.h>
typedef struct IDform
{char sname[20];
char gname[20];
char htown[20];
int idnum;
};
void main()
{struct IDform a[20],b[20];
FILE *fp1,*fp2,*fp3;
int order;
int i=0,j=0;

if((fp1=fopen("C:\\Users\\hp\\Documents\\Pelles C Projects\\new\\a.txt","r"))==NULL)
{printf("Can't open the file!\n");
exit (1);
}
while(feof(fp1)==0)
{
fscanf(fp1,"%s%s%s%d",a[i].sname,a[i].gname,a[i].htown,&a[i].idnum);
fprintf(fp1,"%s%s%s%d",a[i].sname,a[i].gname,a[i].htown,&a[i].idnum);
i++;
}
if((fp2=fopen("C:\\Users\\hp\\Documents\\Pelles C Projects\\new\\b.txt","r"))==NULL)
{printf("Can't open the file!\n");
exit (2);
}

fscanf(fp1,"%s%s%s%d",a[i].sname,a[i].gname,a[i].htown,&a[i].idnum);
/*为什么又使用fprintf? */
fprintf(fp1,"%s%s%s%d",a[i].sname,a[i].gname,a[i].htown,&a[i].idnum);

/* fp1 指向的是文本文件,为什么使用二进制读取? */
fread(&a[i],sizeof(a[i]),1,fp1);

......不会,我也是这一块不会。

应该是a,b文档内的人员资料读出来整理好再存入c文档
fprintf(fp1,"%s%s%s%d",a[i].sname,a[i].gname,a[i].htown,&a[i].idnum);
好像有问题。

若是输出中文就会输出乱码.
只能用VC辑译器运行才能输出中文.