什么时候,还是要靠自己
程序代码:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
FILE* p1 = NULL, * p2 = NULL, * fp = NULL;
char temp;
int i, j;
char a[100] = { 0 }, b[100] = {0};
int count1 = 0, count2 = 0;
p1 = fopen("A.txt", "r");
p2 = fopen("B.txt", "r");
if ((fp = fopen("C.txt", "w")) == NULL)
{
printf("打开文件失败\n");
getchar();
exit(1);
}
for (i = 0;!feof(p1); i++)
{
fscanf(p1, "%c", &a[i]);
count1++;
}
for (i = 0;!feof(p2); i++)
{
fscanf(p2, "%c", &b[i]);
count2++;
}
strcat(a, b);
for (i = 0; i < count1 + count2-2; i++)
{
for (j = 0; j < count1 + count2 - i - 1-2; j++)
{
if (a[j] > a[j + 1])
{
temp = a[j];
a[j] = a[j + 1];
a[j + 1] = temp;
}
}
}
for (i = 0; i < count1 + count2-2; i++)
{
printf("%c",a[i]);
}
fprintf(fp, "%s\n", a);
fclose(p1);
fclose(p2);
fclose(fp);
getchar();
return 0;
}