getchar()
QNX SDP8.0C Library ReferenceAPIDeveloper
Get a character from stdin
Synopsis:
#include <stdio.h>
int getchar( void );
Library:
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
Description:
The getchar() function is equivalent to getc() on the stdin stream.
Returns:
- If successful, getchar() returns the next character from stdin,
  cast as 
(int)(unsigned char). - If the end-of-file indicator for the stream is set or the end of the file has been reached, getchar() sets the end-of-file indicator and returns EOF.
 - If an error occurred, getchar() sets the error indicator for the stream, sets errno, and returns EOF.
 
Examples:
#include <stdio.h>
#include <stdlib.h>
int main( void )
{
    FILE *fp;
    int c;
    /* Get characters from "file" instead of
     * stdin.
     */
    fp = freopen( "file", "r", stdin );
    while( ( c = getchar() ) != EOF ) {
        putchar(c);
    }
    fclose( fp );
    
    return EXIT_SUCCESS;
}
Classification:
| Safety: | |
|---|---|
| Cancellation point | Yes | 
| Signal handler | No | 
| Thread | Yes | 
Page updated: 
