C Standard Libraries C++

getc()

Declaration

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

Description

This function returns the character from the stream "qpStream" at the current file pointer's location and advances the file pointer. If the function is not successful, it returns EOF.

Input File

getc() Input File

Example

#include <cstdio>

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

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

    // Get the first character in the file.
    int iRet = getc(qpFile);
    printf("Read in: %c\n", (char)iRet);
    fclose(qpFile);

    return 0;
}

Output

getc() Output
 

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