Keil Logo

GENERAL: EXITING SCANF WHEN NO SERIAL DATA IS READY


Information in this article applies to:

  • C166 Version 3.12 and Later
  • C251 Version 2.14 and Later
  • C51 Version 5.50 and Later

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

  • Refer to the scanf library function in your compiler user's guide
  • Refer to the getkey library function in your compiler user's guide
  • Refer to the putchar library function in your compiler user's guide

Last Reviewed: Monday, November 15, 2004


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.