帮忙看看文件里字符排序的问题
#include "stdio.h"#include "stdlib.h"
void main()
{
FILE *fp1,*fp2,*fp3;
char ch;
char c[100];
char temp;
int l1,n;
fp1=fopen("13_5_A.txt","r");
if (fp1==NULL)
{
printf("can't open the file 13_5_a_A");
exit(0);
}
fp2=fopen("13_5_B.txt","r");
if (fp2==NULL)
{
printf("can't open the file 13_5_a_A");
exit(0);
}
printf("file:A\n");
for (int i=0;(ch=fgetc(fp1))!=EOF;i++)
{
c[i]=ch;
putchar(c[i]);
}
l1=i;
fclose(fp1);
printf("\nfile:B\n");
for (i=l1;(ch=fgetc(fp2))!=EOF;i++)
{
c[i]=ch;
putchar(c[i]);
}
printf("\n");
fclose(fp2);
n=i;
for (i=0;i<n;i++)
{
for (int j=i+1;j<n;j++)
{
if(c[i]>c[j])
{
temp=c[i];
c[i]=c[j];
c[i]=temp;
}
}
}
fp3=fopen("13_5_C.txt","w");
if (fp3==NULL)
{
printf("can't open the file 13_5_a_A");
exit(0);
}
printf("file:C\n");
for (i=0;i<n;i++)
{
// fprintf(fp3,"%c",c[i]);
putc(c[i],fp3);
putchar(c[i]);
}
printf("\n");
fclose(fp3);
}
我将两个文件里的字符读取存在C数组中 对C数组排序后读到13_5_C文件中,但实现不了排序功能