Keil Logo

C51: CLEARING THE SCANF INPUT STREAM


Information in this article applies to:

  • C51 Version 5.50a
  • C51 Version 6.12

QUESTION

I'm using the scanf function and it works as expected, but sometimes it does not wait for a key to be pressed before returning. It seems that there are characters from previous scanf commands in the I/O stream. Is there a function I can call to clear the input buffer before I call scanf?

ANSWER

scanf has an input buffer that holds previous characters from the I/O stream. Use the following small assembler function to clear this input buffer.

; CLR_CHAR.A51
EXTRN BIT (?C?charloaded)
PUBLIC clear_getchar

?PR?clear_getchar SEGMENT CODE
RSEG ?PR?clear_getchar

clear_getchar:    CLR  ?C?charloaded
                  RET

                  END

FORUM THREADS

The following Discussion Forum threads may provide information related to this topic.

Last Reviewed: Thursday, September 20, 2001


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.