Prints formatted data to a stream.
#include <stdio.h>
int fprintf( FILE *stream, const char *format[[, argument]]...);
stream | Pointer to FILE structure | |
format | Format-control string | |
argument | Optional arguments |
The fprintf function formats and prints a series of characters and values to the output stream. Each argument (if any) is converted and output according to the corresponding format specification in format.
The format argument has the same form and function that it does for the printf function; see the Remarks section for the printf function for more information on format and argument.
The fprintf function returns the number of characters printed, or a negative value in the case of an output error.
Standards:ANSI, UNIX
16-Bit:DOS, QWIN, WIN
32-Bit:DOS32X
_cprintf, fscanf, printf, sprintf
/* FPRINTF.C: This program uses fprintf to format various data and
* print them to the file named FPRINTF.OUT. It then displays
* FPRINTF.OUT on the screen using the system function to invoke
* the DOS 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" );
}
this is a string
10
1.500000