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

The Function Fgetpos ()() in C

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

Table of Contents

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

Declare the Function Fgetpos ()() in C

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

 int fgetpos ( FILE * stream , fpos_t * pos ) 

Parameters

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

Pos - This is the pointer to an fpos_t object.

Returns the value

This function returns 0 if successful, and returns a value other than 0 if there is an error.

For example

The following C program illustrates the usage of the fgetpos () 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 ( "Noi dung nay se ghi de phan noi dung da co truoc trong file" , fp ); fclose ( fp ); return ( 0 ); } 

Compile and run the above program to create a Bait file. Txt With the following content. First we take the original location of the file using the Fgetpost () Function and then we write Hello, World! In this file, then we use the fsetpos () function to restore the cursor to the beginning of the file and then overwrite the file with the following content:

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

 #include int main () { FILE * fp ; int c ; int n = 0 ; 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 lesson: Function fflush () in C

Next lesson: Function fopen () 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.