GetChar
Function Name: GetChar
Functions: Reading characters from stdin stream
Usage: int getchar (void);
Annotations:
GetChar has a return value of type int. When the program calls GetChar. The program waits for the user to press the key. The characters entered by the user are stored in the keyboard buffer. Until the user presses carriage return (the carriage return character is also placed in the buffer). When the user types in a carriage return, GetChar only begins to read one character at a time from the stdin stream. The return value of the GetChar function is the ASCII code of the first character entered by the user, such as error return-1, and the character entered by the user is echo to the screen. If a user enters more than one character before pressing ENTER, Other characters specifier remain in the keyboard cache, waiting for subsequent getchar calls to be read. That is, subsequent GetChar calls do not wait for the user to press the key, but to read the characters in the buffer directly until the characters in the buffer are read to wait for the user to press the key.
Getch and GetChar basic functions are the same, the difference is getch directly from the keyboard to get the key value, wait for the user to press ENTER, as long as the user presses a key, Getch immediately return, Getch return value is the user entered the ASCII code, Error return-1. The characters you enter do not echo back to the screen. Getch functions are often used in program debugging, when debugging, display the relevant results in a critical position for viewing, and then suspend the program with the Getch function, and the program continues to run when you press any key.
program Example:
#include <stdio.h>
int main (void)
{
int c;
/* Note: GetChar reads from stdin and are line buffered-this means it won't return until to press
ENTE R. *
/while ((c = GetChar ())!= ' \ n ')
printf ("%c", c);
return 0;
}
Note: You can use the GetChar () function to wait for the programmer to press the keyboard to return to the editing interface after the program has finished debugging, use: At the end of the main function, returns 0; before adding GetChar ();
View a full set of articles: Http://www.bianceng.cn/Programming/C/201212/34807.htm