|
|
#include <stdio.h>int fsetpos(stream, pos) FILE *stream; const fpos_t *pos;
The function clears the end-of-file indicator and undoes any effects of the ungetc(stream). After calling fsetpos, the next operation on stream may be either input or output.
ANSI X3.159-1989 Programming Language -- C
.
#include <stdio.h>FILE *stream; fpos_t pos[]; int val; char list[100];
main() { /* open file1 */ if ((stream = fopen ("file1","rb")) == NULL) printf ("Trouble opening file\n"); else { /* Read some data */ fread (list, sizeof(char), 100, stream); /* Save current position */ if (fgetpos (stream, &pos) != 0) perror("fgetpos error"); /* Read some more */ fread (list, sizeof(char), 100, stream); /* Return to saved position */ if (fsetpos (stream, &pos) != 0) perror ("fsetpos error"); } }
This program opens the file named file1 and reads 100 characters. It then uses fgetpos to find and save the file position pointer. After performing another read, the program calls fsetpos to restore the file pointer to the saved position.