/* 使用ftell函数获取位置指针的位置 */ #include <stdio.h> int main(void) { FILE * fp = NULL; fp = fopen("file1.txt", "r"); if (NULL == fp) { printf("Can't open file \"test.txt\""); return -1; } printf("Before writing:\n"); printf("ferror(fp) = %d\n", ferror(fp)); fputc('a', fp); printf("After writing:\n"); printf("ferror(fp) = %d\n", ferror(fp)); fclose(fp); fp = NULL; return 0; }