我该如何获取文件指针的当前行位置?
没有获取当前行的函数,您需要自己跟踪它。可以像这样:
FILE *file;
int c, line;
file = fopen("myfile.txt", "rt");
line = 0; /* 1 if you want to call the first line number 1 */
while ((c = fgetc(file)) != EOF) {
if (c == '\n')
++line;
/*
... do stuff ...
*/
}
ftell
可能不会直接返回文本模式流的有意义的内容。 - jamesdlin