fsetpos() (Set File Position) in C
Last Updated :
21 Sep, 2023
The fsetpos() function moves the file position indicator of the given file stream to the specified position. When fsetpos() is executed, the end-of-file indicator is reset. fsetpos() function is a part of <cstdio> header file in C Standard Library.
Syntax of fsetpos()
int fsetpos(FILE *stream, const fpos_t *pos)
Parameters
- stream – This is the pointer to a FILE object that identifies the stream.
- position – This is the pointer to a fpos_t object containing the desired value of the position indicator.
Return Value
- If it is successful, it returns zero otherwise returns a nonzero value.
C Program to Illustrate the use of fsetpos()
C
#include <stdio.h>
int main()
{
FILE * fp;
fpos_t position;
fp = fopen ( "myfile.txt" , "w+" );
fgetpos (fp, &position);
fputs ( "HelloWorld!" , fp);
fsetpos (fp, &position);
fputs ( "geeksforgeeks" , fp);
fsetpos (fp, &position);
char arr[50];
fgets (arr, 14, fp);
puts (arr);
fclose (fp);
return (0);
}
|
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...