getchar(3C)
_________________________________________________________________
getchar macro
Read a single character from the standard input.
_________________________________________________________________
Calling Sequence
#include <stdio.h>
int c;
c = getchar();
where c = next character, or -1 if an error occurred.
Description
Use the getchar macro to read a single character from the
standard input. Since getchar is a macro, it produces more in-
line code than the corresponding call to fgetc with argument
stdin, but the code executes faster. You cannot pass getchar as
a parameter to a function or take its address, since it is a
macro and not a function. Use fgetc in these instances instead.
Returns
The getchar macro returns the next character, or -1 if an error
occurs.
Related Functions
See also the getc and putchar macros, and the fgetc function.
Example
/* Program test for the getchar() macro */
#include <stdio.h>
#define EOF '\n'
char c;
main(argc, argv)
int argc;
char *argv[];
{
putchar(c = '?');
DG/UX 4.00 Page 1
Licensed material--property of copyright holder(s)
getchar(3C)
while (c != EOF) {
putchar(c = ' ');
putchar(c = getchar());
}
}
If you call the program test and respond to the ? prompt with
? Stretch me out.
you generate the output
S t r e t c h m e o u t .
DG/UX 4.00 Page 2
Licensed material--property of copyright holder(s)