(1) getch () and getche () Functions
Both functions read one character from the keyboard. The call format is:
Getch ();
Getche ();
The difference between the two is that the getch () function does not display the characters read back on the display screen, while the getche () function does ()
The function returns the characters read to the display screen.
Example 1:
# Include <stdio. h>
Main ()
{
Char C, ch;
C = getch ();/* read a character from the keyboard and do not return it to the character variable C */
Putchar (c);/* output this character */
Ch = getche ();/* read a character explicitly from the keyboard and send it to the character variable ch */
Putchar (ch );
}
With the features of ECHO and non-Echo, these two functions are often used to complete the pause during interactive input.
.
Example 2:
# Include <stdio. h>
Main ()
{
Char c, s [20];
Printf ("Name :");
Gets (s );
Printf ("Press any key to continue ...");
Getch ();/* wait for any input key */
}
(2) getchar () function
The getchar () function also reads a character from the keyboard and brings it back to the display. It corresponds to the first two functions.
The difference is: The getchar () function waits for the input to end until Press enter. All input words before press ENTER
Are displayed on the screen one by one. But only the first character is used as the return value of the function.
The call format of the getchar () function is:
Getchar ();
Example 3:
# Include <stdio. h>
Main ()
{
Char C;
C = getchar ();/* read characters from the keyboard until the carriage return ends */
Putchar (c);/* display the first character of the input */
Getch ();/* wait for any key */
}
Example 4
# Include <stdio. h>
Main ()
{
Char C;
While (C = getchar ())! = '/N')/* Each getchar () reads one character in sequence */
Printf ("% c", c);/* output as is */
Getch ();/* wait for any key */
}
Getch () is a character that is waiting to be read from the keyboard and is not displayed on the screen.
Getche () display and on-screen
If you want to use GETCH () when using TC in WIN, include this header file: <conio. h>
Use this package # include <curses. h> in LINUX. If an error is reported during connection compilation, run the following command: (gcc-lncurses)
For example, gcc-o telephonum-lncurses telephonum. c
In addition:
// Clrscr (); clrscr is unique to TC. This function is not available in other C Language Environments. The function is clear screen!
System ("cls"); // system ("cls"); to replace clrscr (); more common, better compatibility. The system () function is in # include <stdlib. h>.
Printf ("/tADD new subscriber details ");