fprintf

 

Description

Formats and prints a series of characters and values to the output stream.

Syntax

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

Parameters

stream
Pointer to FILE structure
format
Format-control string
...

Return

Returns the number of bytes written. Returns a negative value instead when an output error occurs.

Examples

EX1

//The following example uses fprintf to format various data and print it to the file named fprintf.out.

void test_fprintf()
{
    FILE *stream;
    int    i = 10;
    double fp = 1.5;
    char   s[] = "this is a string";
    char   c = '\n';
    
    stream = fopen( "fprintf.out", "w" );
    if(stream == NULL)
        printf( "The file fprintf.out was not opened\n" );
    
    fprintf( stream, "%s%c", s, c );
    fprintf( stream, "%d\n", i );
    fprintf( stream, "%f\n", fp );
    fclose( stream );
}

Remark

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.

See Also

fscanf

Header to Include

origin.h

Reference