Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Borland C++ 2.x ( with Turbo C ) - <b>fsetpos() set current file pointer position</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 fsetpos()               Set Current File Pointer Position

 #include <stdio.h>

 int        fsetpos(stream,pos);
 FILE         *stream;
 const fpos_t *pos;

    fsetpos() sets the file pointer associated with 'stream' to the
    position pointed to by 'pos'. 'pos' is the value obtained by a
    previous call to fgetpos(). fsetpos() clears the end-of-file
    indicator and discards any character pushed back using ungetc().
    After calling fsetpos(), the next operation on a file can be input or
    output.

    The type fpos_t is defined in <stdio.h> as:

     typedef long fpos_t;

       Returns:     On success, 0 is returned. On failure, a non-zero
                    value is returned.

   -------------------------------- Example ---------------------------------

    The following statements get the current file pointer.

           #include <stdio.h>

           main()
           {
               FILE *in;
               fpos_t filepos;
               int result;
               char *tst = "add text to file...";

               if ((in = fopen("info.dat","a+")) != NULL)
                   {
                   fprintf(in,"%s",tst);
                   if ((result = fgetpos(in,&filepos)) == 0) {
                       printf("file position: %ld\n",filepos);
                       if ((result = fsetpos(in,&filepos)) == 0)
                           printf("set file position: %ld\n",filepos);
                   fprintf(in,"the end");
                   }
                   else
                       printf("unable to get file position\n");
                   fclose(in);
               }
               else
                   printf("unable to open file\n");
           }


See Also: fgetpos() fseek()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson