The difference between C language-getchar () and Getch ()

Source: Internet
Author: User

GetChar () and Getch () are all functions used to capture input characters from the keyboard, what is the difference between them?
The GetChar () function takes the character as follows: When executed to the GetChar () function, the user enters the character from the keyboard and caches it in buffer in memory, and GetChar () actually assigned the buffer's word to the variable only when the ENTER key is pressed. At the same time, the ENTER key is also stored in buffer, and another getchar () function must be used to get the enter value in buffer. This is the biggest problem with the GetChar () function. Of course, the input cache also has a benefit-when the user enters the wrong character, the input character can be modified by BACKSPACE.
Getch () solves the problem of the GetChar function enter key, the Getch () function, when executed, directly to the keyboard input Word assigned value to the variable, and omitted the steps of the cache.
Thus, the Getch () function can achieve a higher efficiency than the getchar, and the disadvantage is that the value of the wrong input cannot be corrected.

The difference between C language-getchar () and Getch ()

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.