ftell()函数ftell
语法:
1 2 |
?? #include <stdio.h> ?? long ftell( FILE *stream ); |
ftell()函数返回stream(流)当前的文件位置,如果发生错误返回-1.
函数 ftell 用于得到文件位置指针当前位置相对于文件首的偏移字节数。在随机方式存取文件时,由于文件位置频繁的前后移动,程序不容易确定文件的当前位置。
该函数对大于231-1文件,即:2.1G以上的文件操作时可能出错。
1 2 3 4 5 6 7 8 9 10 11 |
#include <stdio.h> int main(void) { FILE *stream; stream = fopen("MYFILE.TXT", "w+"); fprintf(stream, "This is a test"); printf("The file pointer is at byte \ %ld\n", ftell(stream)); fclose(stream); return 0; } |