C语言写出文件合并的代码

想求助一下。。。。。我写出来之后在f.txt里面是乱码,有无大佬帮忙看看代码?

#include<stdio.h>
#include<stdlib.h>
#define N 20


int main()
{
	FILE *fp1, *fp2, *fp;
	int i, j, temp;
	int f[N];
	if((fp1 = fopen("f01.txt", "r")) == NULL)
	{
		printf("error");
		exit(1);
	}
	if((fp2 = fopen("f02.txt", "r")) == NULL)
	{
		printf("error");
		exit(1);
	}
	if((fp = fopen("f.txt", "w")) == NULL)
	{
		printf("error");
		exit(1);
	}
	
	fread(f, sizeof(f), 10, fp1);
	fread(f, sizeof(f), 10, fp2);

	for(i=0; i<N; i++)
	{
		for(j=0; j<N-i; j++)
		{
			if(f[j] > f[j+1])
			{
				temp = f[j];
				f[j] = f[j+1];
				f[j+1] = temp;
			}
		}
	}

	fprintf(fp, "%d", f[N]);

	fclose(fp1);
	fclose(fp2);
	fclose(fp);

	return 0;
}

乱码是因为字符集不匹配导致的,你要保证你打开的文件字符集与编译后的程序一致才行。

img