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>fgetpos() get current file pointer position</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 fgetpos()               Get Current File Pointer Position

 #include   <stdio.h>

 int        fgetpos(stream,pos);
 FILE       *stream;
 fpos_t     *pos;

    fgetpos() gets the current position of the file pointer associated
    with 'stream' and stores it in the location pointed to by 'pos'.

    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: fseek() fsetpos()

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