fprintf, fwprintf

Print formatted data to a stream.

intfprintf(FILE*stream,constchar*format [, argument ]...);

intfwprintf(FILE*stream,constwchar_t*format [, argument ]...);

Function Required Header Compatibility
fprintf <stdio.h> ANSI, Win 95, Win NT
fwprintf <stdio.h> or <wchar.h> ANSI, Win 95, Win NT

For additional compatibility information, see Compatibility in the Introduction.

Libraries

LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version

Return Value

fprintf returns the number of bytes written. fwprintf returns the number of wide characters written. Each of these functions returns a negative value instead when an output error occurs.

Parameters

stream

Pointer to FILE structure

format

Format-control string

argument

Optional arguments

Remarks

fprintf formats and prints a series of characters and values to the output stream. Each function argument (if any) is converted and output according to the corresponding format specification in format. For fprintf, the format argument has the same syntax and use that it has in printf.

fwprintf is a wide-character version of fprintf; in fwprintf, format is a wide-character string. These functions behave identically otherwise.

Generic-Text Routine Mappings

TCHAR.H Routine _UNICODE & _MBCS Not Defined _MBCS Defined _UNICODE Defined
_ftprintf fprintf fprintf fwprintf

For more information, see Format Specifcations.

Example

/* FPRINTF.C: This program uses fprintf to format various
 * data and print it to the file named FPRINTF.OUT. It
 * then displays FPRINTF.OUT on the screen using the system
 * function to invoke the operating-system TYPE command.
 */

#include <stdio.h>
#include <process.h>

FILE *stream;

void main( void )
{
   int    i = 10;
   double fp = 1.5;
   char   s[] = "this is a string";
   char   c = '\n';

   stream = fopen( "fprintf.out", "w" );
   fprintf( stream, "%s%c", s, c );
   fprintf( stream, "%d\n", i );
   fprintf( stream, "%f\n", fp );
   fclose( stream );
   system( "type fprintf.out" );
}

Output

this is a string
10
1.500000

Stream I/O Routines

See Also   _cprintf, fscanf, sprintf