C Language: fprintf function(Formatted File Write)

In the C Programming Language, the fprintf function writes formatted output to stream.


The syntax for the fprintf function in the C Language is:

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

Parameters or Arguments


The stream where the output will be written.


Describes the output as well as provides a placeholder to insert the formatted string. Here are a few examples:

Format Explanation Example
%d Display an integer 20
%f Displays a floating-point number in fixed decimal format 50.750000
%.1f Displays a floating-point number with 1 digit after the decimal 12.9
%e Display a floating-point number in exponential (scientific notation) 3.550000e+01
%g Display a floating-point number in either fixed decimal or exponential format depending on the size of the number (will not display trailing zeros) 14.7


The fprintf function returns the number of characters that was written. If an error occurs, it will return a negative value.

Required Header

In the C Language, the required header for the fprintf function is:

#include <stdio.h>

Applies To

In the C Language, the fprintf function can be used in the following versions:

  • ANSI/ISO 9899-1990

stdio.h Functions