Use C ftell function to get the file pointer position
Syntax
C ftell function has the following syntax.
long int ftell(FILE *stream);
Header
C ftell function
is from header file stdio.h
.
Description
C ftell function returns the value for the file position pointer.
Valid for binary file and invalid for text file.
C ftell function returns -1
on failure.
Example
Get file pointer position using C ftell function.
#include <stdio.h>
#include <stdlib.h>
//from ww w . ja va 2s. c o m
int main(void){
FILE *fp;
if((fp=fopen("test", "rb")) == NULL) {
printf("Cannot open file.\n");
exit(1);
}
int i;
if((i=ftell(fp)) == -1L)
printf("A file error has occurred.\n");
fclose(fp);
}