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

Function Vfprintf ()() in C

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

Table of Contents

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

Declare the Function Vfprintf ()() in C

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

 int vfprintf ( FILE * stream , const char * format , va_list arg ) 

Parameters

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

Format - This is the string containing the text to be 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

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 recorded will be returned, otherwise a negative number will be returned.

For example

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

 #include #include void WriteFrmtd ( FILE * stream , char * format , .) { va_list args ; va_start ( args , format ); vfprintf ( stream , format , args ); va_end ( args ); } int main () { FILE * fp ; fp = fopen ( "baitapc.txt" , "w" ); WriteFrmtd ( fp , "Diem %d cho chat luong n" , 10 ); fclose ( fp ); return ( 0 ); } 

Compiling and running the above program will open the baitpc. Txt to write to the current directory and will write the following:

Now monitor the above file contents 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 produce the following results:

According to Tutorialspoint

Previous lesson: sprintf () function in C

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