ftell
语法:
#include <stdio.h> long ftell( FILE *stream ); |
ftell()函数返回stream(流)当前的文件位置,如果发生错误返回-1.
#include <stdio.h>
int main()
{
FILE *file;
file = fopen("E:\\C\\vscode\\C\\file_io\\user.txt", "r");
if(!file)
{
puts("open fail");
return -1;
}
long offset;
offset = ftell(file);//get location of file
printf("output file location:%ld",offset);
fgetc(file);
offset = ftell(file);//get location of file
printf("output file location:%ld",offset);
return 0;
}
output file location:0output file location:1
PS E:\C>