Use fsetpos function to move file position pointer
Syntax
C fsetpos function has the following syntax.
int fsetpos(FILE *stream, const fpos_t *position);
Header
C fsetpos function
is from header file stdio.h
.
Description
C fsetpos function moves the file position pointer. This value is from fgetpos()
.
C fsetpos function returns zero on success or nonzero on failure.
Example
Move file position pointer using C fsetpos function.
#include <stdio.h>
#include <stdlib.h>
//from w ww. j a va 2s . c o m
int main(int argc, char *argv[])
{
FILE *fp;
fpos_t file_loc;
if((fp=fopen("test","r"))==NULL) {
printf("Cannot open file.\n");
exit(1);
}
fgetpos(fp, &file_loc);
fsetpos(fp, &file_loc);
fclose(fp);
}