fwrite()

Declaration

size_t fwrite(const void* kvpBuf, size_t qSize, size_t qCount, FILE* qpStream);

Description:

This function writes "qCount" entries of size "qSize" bytes from the buffer "kvpBuf" to the stream given by "qpStream." The function returns the number of entries actually written to the stream, which may be less than "qCount" if an error occurs.

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;
    }

    char cpBuffer[] = "\nC++ Reference";
    size_t qBytes = 0;
    // Write the entire buffer without the null terminator.
    qBytes = fwrite(cpBuffer, 1, sizeof(cpBuffer) - 1, qpFile);
    printf("Bytes Written = %i\n", qBytes);

    fclose(qpFile);

    return 0;
}

Input File:

fwrite() Input File

Output File:

fwrite() Output File

Output:

fwrite() Output