文件中文读取和存储的问题
从A,B文件读入两个字符串,然后排序存放在C文件中其中B文件中有中文,读入的时候可以打印出来。char是1个字节,装不下一个中文。我想知道在什么地方修改,把中文存放到C文件中,同时也能打印出中文。
print file A :
I LOVE CHINA
print file B :
I LOVE 朱晓燕
Print file C :
涎粥忐 ACEEHIIILLNOOVV
Process returned 0 (0x0) execution time : 0.379 s
Press any key to continue.
程序代码:
#include<stdio.h> #include<stdlib.h> int main() { void file(); file(); return 0; } void file() { FILE* fp; char C[100], ch; int i, j, n, i1, gap, temp; if ((fp = fopen("C:\\Users\\73889\\Desktop\\A.txt", "r"))==NULL) printf("Can not open file!\n"); printf("print file A :\n"); for( i = 0; (ch = fgetc(fp)) != EOF; i++) { C[i] = ch; putchar(C[i]); } fclose(fp); printf("\n"); if ((fp = fopen("C:\\Users\\73889\\Desktop\\B.txt", "r"))==NULL) printf("Can not open file!\n"); printf("print file B :\n"); i1 = i; for (i = i1; (C[i] = fgetc(fp)) != EOF; i ++) putchar(C[i]); fclose(fp); n = i; for(gap = n / 2; gap > 0; gap /= 2) for(i = gap; i < n; i++) for(j = i - gap; j >= 0 && C[j] > C[j + gap]; j -= gap) { temp = C[j]; C[j] = C[j + gap]; C[j + gap] = temp; } printf("\nPrint file C :\n"); fp = fopen("C:\\Users\\73889\\Desktop\\C.txt", "w"); for (i = 0; i < n; i++) { fputc(C[i], fp); putchar(C[i]); } printf("\n"); fclose(fp); return ; }