Syntax
#include <stdio.h> int fprintf(FILE *stream, const char *format-string, argument-list);Description
fprintf formats and writes a series of characters and values to the output stream. fprintf converts each entry in argument-list, if any, and writes to the stream according to the corresponding format specification in the format-string.
The format-string has the same form and function as the format-string argument for printf. See printf for a description of the format-string and the argument list.
In extended mode, fprintf also converts floating-point values of NaN and infinity to the strings "NAN" or "nan" and "INFINITY" or "infinity". The case and sign of the string is determined by the format specifiers. See Infinity and NaN Support for more information on infinity and NaN values.
fprintf returns the number of bytes printed or a negative value if an output error occurs.
This example sends a line of asterisks for each integer in the array count to the file myfile. The number of asterisks printed on each line corresponds to an integer in the array.
#include <stdio.h> int count[10] = { 1, 5, 8, 3, 0, 3, 5, 6, 8, 10 } ; int main(void) { int i,j; FILE *stream; stream = fopen("myfile.dat", "w"); /* Open the stream for writing */ for (i = 0; i < sizeof(count)/sizeof(count[0]); i++) { for (j = 0; j < count[i]; j++) fprintf(stream, "*"); /* Print asterisk */ fprintf(stream, "\n"); /* Move to the next line */ } fclose(stream); return 0; /**************************************************************************** The output data file myfile.dat should contain: * ***** ******** *** *** ***** ****** ******** ********** ****************************************************************************/ }Related Information