We can randomly position file pointer at any position in the data file. There are two functions to do this:
1. fseek() function
fseek() function is used to take file pointer to a particular position data file. Syntax: fseek(Fpointer, Position, Initial);
Fpointer is name of file pointer variable.
Position number of characters to be jumped.
Initial specifies the position from where file pointer should be jumped. It can three values :
0: From the beginning of file.
1: Current position.
2: End of file
|Program of fseek() function.|
char line , s;
s=getc(f); /*5th Character read from file*/
|Contents of file are=This is file
2. ftell() function
This function tells the current position of file pointer .
Fpointer is the name of file pointer variable.
|Program of ftell() function.|
//To read a string value from a fileprintf(“\nContents of file are=”);
printf(“\nFile pointer is at position %d”,n);
|Contents of file are=i love india
File pointer is at position 11