In that year, I learned Linux C-getch () step by step.

Source: Internet
Author: User

 

Http://baike.baidu.com/view/675106.htm Getch ()

Header file: conio. h

Function purpose: Read a character from the console

Function prototype: int getch (void)

Returned value: read characters

For example:

Char ch; or Int ch;

Getch (); or CH = getch ();

Use getch (); wait for you to press any key, and then continue to execute the following statement;

Use CH = getch (); after you press any key, assign the ASCII code corresponding to the key character to CH, and then execute the following statement.

Easy to troubleshoot:

1. the header file is conio. h. Instead of stdio. h.

2. Call initscr () before use, and call endwin () at the end (). Otherwise, the function does not contain any characters.

The returned results.

3. on different platforms, enter the carriage return. getch () returns different values, while getchar () returns 10 (\ n) in a unified manner)

1) on Windows, the Enter key generates two escape characters \ r \ n. Therefore, getch returns 13 (\ r ).

2) in UNIX and Linux systems, the Enter key only produces \ n, so getch returns 10 (\ n ).

3) The enter key in Mac OS generates \ r, so getch returns 13 (\ r ).

Getch (); is not a function in Standard C and does not exist in C. Therefore, pay attentionProgramPortability. Chinese C language beginners often use getch (); to pause the program and do not know the function source. We recommend that you use getchar (); (if possible) to replace this function or replaceCompiler.

After completing the mini 64 10 porting, I plan to share my previous Linux C notes with you. If you have any support, I hope you can point it out. Thank you !!

Reprinted please indicate the source: http://blog.csdn.net/muge0913/article/details/7296072

 

 

 

 

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.