Name
fprintf
Synopsis
Writes formatted output to an open file
#include <stdio.h> intfprintf( FILE * restrictfp, const char * restrictformat, ... );
The fprintf() function is
similar to printf(), but writes
its output to the stream specified by fp
rather than to stdout.
Example
FILE *fp_log;
time_t sec;
fp_log = fopen("example.log", "a");
if ( fp != NULL)
{
time(&sec);fprintf( fp_log, "%.24s Opened log file.\n", ctime( &sec ) );
}This code appends the following output to the file example.log:
Wed Dec 8 21:10:43 2004 Opened log file.
See Also
printf(), sprintf(), snprintf(), declared
in stdio.h; vprintf(), vfprintf(), vsprintf(), vsnprintf(), declared in stdio.h and stdarg.h; the wide-character functions
wprintf(), fwprintf(), swprintf(), declared
in stdio.h and wchar.h; vwprintf(), vfwprintf(), and vswprintf(), declared in stdio.h, wchar.h, and stdarg.h; the scanf() input
functions. Argument conversion in the printf() family of
functions is described under printf() in this
chapter.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access