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

Function Fprintf ()() in C

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

Table of Contents

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

Declare the Function Fprintf ()() in C

Below is the declaration for fprintf () in C:

 int fprintf ( FILE * stream , const char * format , .) 

Parameters

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

Format - This is a string that contains the text written to Stream. It may optionally contain formatting tags that can be embedded that are replaced by values defined in subsequent additional parameters and formatted as required. Prototype tags of the format % [flags] [width] [. Precision] [length] specifier , explained as follows:

Character specifier Character d or i Decimal integer with the sign e Scientific symbol (mantissa / exponent) uses the character e E Scientific notation (mantissa / exponent) using characters E f Actual floating point number Decimal g Short use of% e or% f G Compact use of% E or% fo Octal number signed s Character string u Unsigned decimal number x Hexadecimal integers mark X Unsigned hexadecimal integers (uppercase letters) p Pointer address n Do not print anything% characters

The left side pad (left-pad) of the number with the 0s instead of the spaces

Additional parameters - Depending on the format format string, this function may have an additional parameter array, each containing a value to be inserted in place of each% -tag specified in the format parameter, if. This number of parameters should be the same number as% -tags that expect a value.

Returns the value

If successful, the total number of characters written is returned, otherwise a negative number will be returned.

For example

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

 #include #include int main () { FILE * fp ; fp = fopen ( "baitapc.txt" , "w+" ); fprintf ( fp , "%s %s %s %s" , "Chung" , "toi" , "la" , "QTMTeam" ); fclose ( fp ); return ( 0 ); } 

Compiling and running the above program will create a baitapc. Txt

Now use the following C program to monitor the file contents above:

 #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 ); } 

Compile and run the above C program to see the results:

According to Tutorialspoint

Previous article: Function tmpnam () in C

Next lesson: The function printf () 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.