展开全部
你的数组ch末尾是不是忘加0了?
(去掉排序62616964757a686964616fe58685e5aeb931333335323436算法后)应是这样void main()
{
FILE *fp1, *fp2, *fp3;
char ch[255], temp;
int i = 0, j, n;
if ((fp1 = fopen("file1.txt", "r")) == NULL)
{
printf("不能打开源文件!\n");
return;
}
if ((fp2 = fopen("file2.txt", "r")) == NULL)
{
printf("不能打开源文件!\n");
return;
}
if ((fp3 = fopen("file3.txt", "w")) == NULL)
{
printf("不能打开源文件!\n");
return;
}
while (!feof(fp1))
{
ch[i++] = fgetc(fp1);
}
while (!feof(fp2))
{
ch[i++] = fgetc(fp2);
}
ch[i]=0; /* 这一步很重要,不然strlen会判断失误 */
n = strlen(ch);
/*for (i = 0; i
{
for (j = i + 1; j
{
if (ch[i]>ch[j])
{
temp = ch[i];
ch[i] = ch[j];
ch[j] = temp;
}
}
}*/
for (i = 0; i
{
fputc(ch[i], fp3);
putchar(ch[i]);
}
fclose(fp1);
fclose(fp2);
fclose(fp3);
}