fputc

 

Description

The function writes the single character c to a file.

Syntax

int fputc( int c, FILE * stream )

Parameters

c
Character to be written
stream
Pointer to FILE

Return

The function returns the character written. For fputc and _fputchar, a return value of EOF indicates an error. For fputwc and _fputwchar, a return value of WEOF indicates an error.

Examples

EX1

//The following example uses fputc and send a character array to fputc.out

void test_fputc()
{
    char strptr1[] = "This is a test of fputc!!\n";
    char *p;
    FILE *stream = fopen( "fputc.out", "w+t" );
    if(stream != NULL )
    {
        p = strptr1;
        while( (*p != '\0') && fputc( *(p++), stream ) != EOF ) ;
        fclose(stream)
    }
}

Remark

The function writes the single character c to a file at the position indicated by the associated file position indicator (if defined) and advances the indicator as appropriate. In the case of fputc, the file is associated with stream. If the file cannot support positioning requests or was opened in append mode, the character is appended to the end of the stream.

See Also

fgetc

header to Include

origin.h

Reference