fputs()

Declaration

int fclose(FILE* qpStream);

Description:

This function is used to close stream when you are finished using it. The argument "qpStream" is the stream that gets closed. The function returns 0 if the stream was successfully closed and EOF to indicate an error.

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 reading \n",  cpFileName);
        return 1;
    }

    // Append a plus to the end of the file
    int iResult = fputs(" C++ programming", qpFile);

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

    fclose(qpFile);

    return 0;
}

Input File:

fputs() Input File

Output File:

fputs() Output File

Output:

fputs() Output