ARM Technical Support Knowledge Articles

CLEARING THE SCANF INPUT STREAM

Applies to: C51 C Compiler

Answer


Information in this article applies to:


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

Article last edited on: 2001-09-20 00:00:00

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential