Keil Logo

C51: GETCHAR Echoes Characters


Information in this article applies to:

  • C51 Version 5.x
  • C51 Version 6.x

QUESTION

I just discovered that the getchar function in the library echoes characters received.

Is there a getchar that I can use that will not echo characters?

ANSWER

Yes. The default getchar is implemented similar to the following:

char getchar (void)
{
char c;

c = _getkey ();
putchar (c);
return (c);
}

Note that this simple implementation does not account for the ungetchar function.

The following replacement for getchar will return received characters without echoing them:

char getchar (void)
{
return (_getkey ());
}

Again, note that this implementation does not account for the ungetchar function. If you use ungetchar, you must also include that functionality in your implementation of getchar.

SEE ALSO


Last Reviewed: Thursday, February 25, 2021


Did this article provide the answer you needed?
 
Yes
No
Not Sure
 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.