C Standard Libraries C++

putc()

Declaration

int putc(int iChar, FILE* qpStream);

Description

This function writes an ASCII character "iChar" to a the stream "qpStream" at the location of the of the current internal file pointer location. If successful, the function returns the value of the written character. Otherwise, it returns EOF to indicate an error or end-fo-file condition.

Input File

putc() Input File

Output File

putc() Output File

Example

#include <cstdio>

int main()
{
    char* cpFileName = "XoaX.txt";
    // Open an ASCII text file for appending.
    FILE* qpFile = fopen(cpFileName, "a" );

    // Check that the file was opened successfully.
    if (!qpFile) {
        printf("Could not open the file %s\n",  cpFileName);
        return 1;
    }

    // Append a plus sign to the file
    int iRet = putc('+', qpFile);
    // Check the put was successful
    if (iRet != EOF) {
        printf("Character appended: %c\n", (char)iRet);
    }

    fclose(qpFile);

    return 0;
}

Output

putc() Output
 

© 2007–2024 XoaX.net LLC. All rights reserved.