C Language Development Diary

Source: Internet
Author: User

1. Alt + F8 formatting code in visual stadio.

2. The getch () function in C is used to input a char variable, which is often used for screen waiting. For example, if you want to hold the screen content for a moment and prompt the user to press any key, you can use getch ()

Int ch;
_ Cputs ("type 'y' when finished typing keys :");
Do
{
Ch = _ getch ();
Ch = toupper (CH );
} While (Ch! = 'Y ');

_ Putch (CH );
_ Putch ('\ R'); // carriage return
_ Putch ('\ n'); // line feed
Return 0;

Cross-platform methods are used without underscores. The underlined window is used for your own use.

3,

Difference between getch () and getchar () in C

Getchar has an int type return value. when the program calls getchar. the program is waiting for the user to press the button. characters entered by the user are stored in the keyboard buffer. until you press enter (the carriage return character is also placed in the buffer ). the Return Value of the getchar function is the ASCII code of the first character entered by the user. If an error occurs,-1 is returned and the characters entered by the user are displayed on the screen. if you enter more than one character before pressing enter, other characters will be kept in the keyboard cache and will be read by getchar later. that is to say, subsequent getchar calls will not wait for the user to press the key, but will directly read the characters in the buffer until the characters in the buffer are read as the key.
The basic functions of getch and getchar are the same. The difference is that getch directly obtains the key value from the keyboard. If you do not wait for the user to press the Enter key, getch returns immediately, the return value of getch is the ASCII code entered by the user. If an error occurs,-1 is returned. the entered characters are not displayed on the screen. the getch function is often used in program debugging. During debugging, relevant results are displayed in key locations to be viewed. Then, you can use the getch function to pause the program. When you press any key, the program continues to run.

Getch () is an input command that receives a character from the keyboard and does not display it.

The getche () function displays the characters read back to the display screen.
The getchar () function also reads a character from the keyboard and brings it back to the display. It differs from the previous two functions in that the getchar () function waits for the input to end until press enter, and all the input characters 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.

4,

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.