The use of GetChar, C language

Source: Internet
Author: User

#include <stdio.h>


using namespace Std;
/*
Www.quzhuanpan.com
Reprint please be sure to inform
*/
int main ()
{
int i=0;
Char ch[20];
GetChar ();
for (i=0; i<10; i++)
{
Ch[i]=getchar ();//Subsequent characters are continuously read, so the first character cannot be hit.
}//Read the flag is to press ENTER, and the carriage return also as a character
for (i=0; i<10; i++)
{
printf ("%c", Ch[i]);
}
Puts (CH);
return 0;
}
/*getchar is implemented by a macro: #define GETCHAR () getc (stdin). The GetChar has a return value of type int.
When the program calls GetChar. The program waits for the user to press the key.
Characters entered by the user are stored in the keyboard buffer. Until the user presses ENTER (the carriage return character is also placed in the buffer).
When the user types a carriage return, GetChar 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 an error return-1, and the user-entered word echo to the screen. If the user presses ENTER
Before entering more than one character, the other characters inode remain in the keyboard buffer, waiting for subsequent getchar calls to read. That is to say,
Subsequent GetChar calls do not wait for the user to press the key, but to read the characters in the buffer until the characters in the buffer have finished reading.
Just wait for the user to press the key. */

The use of GetChar, C language

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.