fputc()

Declaration

int fputc(int iChar, FILE* qpStream);

Description:

This function writes the character "iChar" to the stream given by "qpStream." If the function is not successful, the value EOF is returned.

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 %s for writing \n",  cpFileName);
        return 1;
    }

    // Append a plus to the end of the file
    int iResult = fputc((int)'+', qpFile);

    if (iResult == EOF) {
        printf("Write Error");
    }

    fclose(qpFile);

    return 0;
}

Input File:

fputc() Input File

Output File:

fputc() Output File

Output:

fputc() Output