成语大全网 - 汉语词典 - c语言词典合并

c语言词典合并

#include <stdio.h>

#include <string.h>

int main()

{

FILE *fp1 = NULL;

FILE *fp2 = NULL;

FILE *fp3 = NULL;

char buf1[100] = {0};

char buf2[100] = {0};

char buf3[200] = {0};

int i;

int j;

int length;

char temp;

fp1 = fopen("A.txt", "r");

fp2 = fopen("B.txt", "r");

fp3 = fopen("C.txt", "w");

fgets(buf1, 99, fp1);

fgets(buf2, 99, fp2);

strcpy(buf3, buf1);

strcat(buf3, buf2);

length = strlen(buf3);

for(i=0;i<length-1;i++)

{

for(j=i+1;j<length;j++)

{

if(buf3[i]>buf3[j])

{

temp = buf3[i];

buf3[i] = buf3[j];

buf3[j] = temp;

}

}

}

fputs(buf3, fp3);

fclose(fp3);

fclose(fp2);

fclose(fp1);

return 0;

}