Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
Miscellaneous
C Library
cassert (assert.h)
cctype (ctype.h)
cerrno (errno.h)
cfloat (float.h)
ciso646 (iso646.h)
climits (limits.h)
clocale (locale.h)
cmath (math.h)
csetjmp (setjmp.h)
csignal (signal.h)
cstdarg (stdarg.h)
cstddef (stddef.h)
cstdio (stdio.h)
cstdlib (stdlib.h)
cstring (string.h)
ctime (time.h)
cstdio (stdio.h)
functions:
clearerr
fclose
feof
ferror
fflush
fgetc
fgetpos
fgets
fopen
fprintf
fputc
fputs
fread
freopen
fscanf
fseek
fsetpos
ftell
fwrite
getc
getchar
gets
perror
printf
putc
putchar
puts
remove
rename
rewind
scanf
setbuf
setvbuf
sprintf
sscanf
tmpfile
tmpnam
ungetc
vfprintf
vprintf
vsprintf
macro constants:
EOF
FILENAME_MAX
NULL
TMP_MAX
objects:
stderr
stdin
stdout
types:
FILE
fpos_t
size_t


fsetpos

function
<cstdio>
int fsetpos ( FILE * stream, const fpos_t * pos );

Set position indicator of stream

Changes the internal file position indicator associated with stream to a new position. The position parameter is a pointer to an fpos_t object whose value shall have been previously obtained with a call to fgetpos.
The End-of-File internal indicator of the stream is cleared after a call to this function, and all effects from previous calls to ungetc are dropped.
On streams open for update (read+write), a call to fsetpos allows to switch between reading and writing.

Parameters

stream
Pointer to a FILE object that identifies the stream.
position
Pointer to a fpos_t object containing a position previously obtained with fgetpos.

Return Value

If successful, the function returns a zero value.
Otherwise, it returns a nonzero value and sets the global variable errno to a positive value, which can be interpreted with perror.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/* fsetpos example */
#include <stdio.h>
int main ()
{
  FILE * pFile;
  fpos_t position;
  pFile = fopen ("myfile.txt","w");
  fgetpos (pFile, &position);
  fputs ("That is a sample",pFile);
  fsetpos (pFile, &position);
  fputs ("This",pFile);
  fclose (pFile);
  return 0;
}


After this code is successfully executed, a file called myfile.txt will contain:
This is a sample

See also