ARM Technical Support Knowledge Articles

EXITING SCANF WHEN NO SERIAL DATA IS READY

Applies to: General Topics

Answer


Information in this article applies to:


SYMPTOMS

I'm using scanf to read formatted input from the serial port. If there is no data ready, I want to exit this routine. How do I do this?

CAUSE

The scanf routine is designed to read input until a character is input that conflicts with the format string. When such a character is read, then and only then does scanf return. So, if there is no input available, scanf just waits.

RESOLUTION

Since scanf does not terminate if no characters are available, you must write your own functions to read and process your input stream. The best place to start is to look at the source code for getkey and putchar. The files getkey.c and putchar.c may be found in the lib directory of your compiler installation.

MORE INFORMATION

Article last edited on: 2004-11-15 16:55:07

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