Clear, practical technology insights BSOD Code Lookup · Windows Error Code Lookup · Wi-Fi Troubleshooting · PC Troubleshooting Checklist

The Function Fsetpos ()() in C

Explore The Function Fsetpos ()() in C with clear explanations, practical examples, and useful tips.

Table of Contents

This guide covers the function fsetpos ()() in c with practical context and easy-to-follow details. Use it to understand the subject and apply the information confidently.

Declare Function Fsetpos ()() in C

Below is the declaration for the fsetpos () function in C:

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

Parameters

Stream - This is the pointer to a FILE object that identifies the Stream.

Pos - This is the pointer to an object fpos_t object containing a previously acquired location with the fgetpos function.

Returns the value

This function returns 0 if successful, or else it returns a nonzero value and sets the global variable errno to a positive value, which can be interpreted with perror.

For example

The following program C illustrates the usage of the fsetpos () function in C:

 #include int main () { FILE * fp ; fpos_t position ; fp = fopen ( "baitapc.txt" , "w+" ); fgetpos ( fp , & position ); fputs ( "Hello, World!" , fp ); fsetpos ( fp , & position ); fputs ( "Dong nay se ghi de phan noi dung da co truoc do" , fp ); fclose ( fp ); return ( 0 ); } 

Compiling and running the above program to create a Baitcap. Txt Will have the following content. First we get the original location of the file using the Fgetpos () Function, and then we write Hello, World! In the file, then we use the fsetpos () function to restore the write pointer to the beginning of the file and then overwrite the file with the following content:

Now follow the contents of the above file by using the following C program:

 #include int main () { FILE * fp ; int c ; fp = fopen ( "baitapc.txt" , "r" ); while ( 1 ) { c = fgetc ( fp ); if ( feof ( fp ) ) { break ; } printf ( "%c" , c ); } fclose ( fp ); return ( 0 ); } 

Compiling and running the above C program will result:

According to Tutorialspoint

Previous article: Function fseek () in C

Next lesson: Function ftell () in C

FAQ

What should I check before following these steps?

Confirm device and software compatibility, save important data, and make sure you have the required permissions, files, and account access.

Why might the process not work?

Common causes include outdated software, missing permissions, incompatible hardware, an unstable connection, or completing a step in the wrong order.

Can I undo the changes if necessary?

That depends on the tool or setting. Use built-in restore options when available, keep a backup, and record the original configuration first.

Discussion

Reader Comments 0

Sign in with email or Google to join the discussion.