[Previous] [Contents] [Index] [Next]

Caution: This version of this document is no longer maintained. For the latest documentation, see http://www.qnx.com/developers/docs.

fputc()

Write a character to a stream

Synopsis:

#include <stdio.h>

int fputc( int c, 
           FILE* fp );

Arguments:

c
The character you want to write.
fp
The stream you want to write the character to.

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The fputc() function writes the character specified by c, cast as (int)(unsigned char), to the stream specified by fp.

Returns:

The character written, cast as (int)(unsigned char), or EOF if an error occurred (errno is set).

Examples:

#include <stdio.h>
#include <stdlib.h>

int main( void )
{
    FILE *fp;
    int c;

    fp = fopen( "file", "r" );
    if( fp != NULL ) {
        while( (c = fgetc( fp )) != EOF ) {
            fputc( c, stdout );
        }
        fclose( fp );
        
        return EXIT_SUCCESS;
    }
    
    return EXIT_FAILURE;
}

Classification:

ANSI, POSIX 1003.1

Safety:
Cancellation point Yes
Interrupt handler No
Signal handler No
Thread Yes

Caveats:

If c is negative, the value returned by this function isn't equal to c -- unless c is -1 and an error occurred :-)

See also:

errno, fgetc(), fopen(), fprintf(), fputchar(), fputs(), putc(), putchar(), puts()


[Previous] [Contents] [Index] [Next]