Pointer to the output stream where the formatted output will be written.
2nd Parameter Type : const char *
Pointer to read-only string
2nd Parameter
Pointer to a null-terminated string specifying the format of the output. It may include format specifiers such as `%d`, `%s`, etc.
3rd Parameter Type : va_list
A data type used to hold information about variable arguments passed to a variadic function. It is initialized with `va_start`, used with `va_arg`, and cleaned up with `va_end`.
3rd Parameter
The variable argument list containing the values to be formatted and written, initialized with `va_start`.
Read more about parameters of vfprintf in parameters section
The vfprintffunction in C language Prints formatted output to the specified stream using a va_list.
vfprintf is similar to fprintf, but instead of taking a variable number of arguments, it takes a va_list that has been initialized by va_start. This function is useful for implementing custom variadic functions that need to forward their arguments to fprintf.
The vfprintffunction takes 3
parameters:
•
FILE * `stream`: Pointer to the output stream where the formatted output will be written.
•
const char * `format`: Pointer to a null-terminated string specifying the format of the output. It may include format specifiers such as `%d`, `%s`, etc.
•
va_list `args`: The variable argument list containing the values to be formatted and written, initialized with `va_start`.
Writes the formatted output to the specified `stream` based on the format string `format` and the values in the `va_list` object `args`. Returns the number of characters written, or a negative value if an error occurs.
The vfprintf function return value :
Returns the number of characters written, or a negative value if an error occurred
Output
This example demonstrates using vfprintf in a custom logging function that can write to different streams.