本文共 1401 字,大约阅读时间需要 4 分钟。
偶尔间发现了一个程序,让我想起了一个问题:一个汉字真的由两个字节存放吗?//文件名字为test.c #include #include #include int main(int argc, char *argv[]) { char ch2; FILE *fp; int i; fp = fopen(argv[1], "rt"); if(fp == NULL) { perror("fopen:"); } while((ch2 = fgetc(fp)) != EOF) { printf("%c", ch2); } fclose(fp); return 0; } |
//文件名字为test.c#include #include #include int main(int argc, char *argv[]) { char ch1[20] = {0}, ch2; FILE *fp; int i = 0, j; fp = fopen(argv[1], "rt"); if(fp == NULL) { perror("fopen:"); } while((ch2 = fgetc(fp)) != EOF) { printf("%c", ch2); ch1[i++] = ch2; } i = strlen(ch1); for(j = 0; j < i - 1; j++) { printf("ch1[%d]=%c\n", j, ch1[j]); } printf("%c%c%c\n", ch1[0], ch1[1], ch1[2]); printf("%c%c\n", ch1[0], ch1[1]); printf("%c%c\n", ch1[1], ch1[2]); fclose(fp); return 0; } |
上一篇:
下一篇:
转载地址:http://wcmti.baihongyu.com/