Home Tutorial C C file fsetpos() function

 
 

Share on Google+Share on Google+
C file fsetpos() function
Posted on: December 24, 2009 at 12:00 AM
Advertisement
This section demonstrates the use of fsetpos() function in C.

C file fsetpos() function

This section demonstrates the use of fsetpos() function in C. The function fsetpos() is used to set the position of the stream to the location indicated by the information in pos. This information is obtained from the function fgetpos().

Its syntax is: fsetpos(File *stream,const fpos_t *pos)

This  function sets the file position and state indicators for the stream pointed to by stream according to the value of the object pointed to by pos, where a value is obtained from the function fgetpos() on the same stream. In the following code, the function fopen(file, "w") open a file and allow to perform write operations. The fputs() function writes the string "That is an example of fsetpos function"  into the file. Then, we have used the fsetpos() function that sets the file position for the stream which allows the fputs() function to replace the string "That" with "This".

Here is the code:

#include <stdio.h>

int main() {
      FILE * pFile;
      fpos_t position;
      pFile = fopen("myfile.txt", "w");
      fgetpos(pFile, &position);
      fputs("That is an example of fsetpos() function", pFile);
      fsetpos(pFile, &position);
      fputs("This", pFile);
      fclose(pFile);
      return 0;
}


Advertisement

Related Tags for C file fsetpos() function:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: December 24, 2009

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com