Function name : fsetpos
Header file : <stdio.h>
Function prototype : int fsetpos(FILE *stream,const fpos_t *pos);
Function : Used to position the file pointer at the specified position. fsetpos saves the position of the file pointer associated with stream in the place pointed by pos.
Parameters : FILE *stream file stream to be located
const fpos_t *pos type fpos_t is defined in stdio.h as the pointer position to be located typeddf long fpos_t;
Return value : 0 on success, non-0 on failure.
Program example : Open the file and obtain the stream pointer position, and output the position
#include<stdio.h>#include<string.h>intmain(void){charstring[]=www.dotcpp.com;fpos_tfilepos;FILE*stream=fopen(test.txt,w+);fwrite(string,strlen( string),1,stream);//Write the string into the file stream fgetpos(stream,&filepos);//Get the pointer position of the file printf(Thefilepointerisatbyte%ldn,filepos);fclose(stream);return0; }
Running results
Thefilepointerisatbyte14