Header file:
stdio.h
Synopsis:
long ftell(FILE *stream);
Description:
Returns the current position of the file pointer on success. Otherwise, -1 is returned.
ftell function C example:
#include<stdio.h>
int main() {
int pos;
FILE *fp;
fp = fopen("input.txt", "rb");
fseek(fp, 5, SEEK_SET);
pos = ftell(fp);
printf("Position of cursor: %d\n", pos);
fclose(fp);
return 0;
}
int main() {
int pos;
FILE *fp;
fp = fopen("input.txt", "rb");
fseek(fp, 5, SEEK_SET);
pos = ftell(fp);
printf("Position of cursor: %d\n", pos);
fclose(fp);
return 0;
}
Output:
jp@jp-VirtualBox:~/cpgms/exp$ cat input.txt
hello world
hello world
hello world
jp@jp-VirtualBox:~/cpgms/exp$ ./a.out
Position of cursor: 5
hello world
hello world
hello world
jp@jp-VirtualBox:~/cpgms/exp$ ./a.out
Position of cursor: 5
No comments:
Post a Comment