分类: C/C++
2009-10-12 21:47:20
//文件名字为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; } |