Keil Logo

C51: SCANF() BEHAVES INCORRECTLY


Information in this article applies to:

  • C51 Version 5.50

SYMPTOMS

When I use scanf() in my program, I cannot enter any data. The function sometimes returns after entering one character and sometimes after two, but it never waits for Enter to be pressed, as it should. It always returns a value of zero and the variables passed to scanf() are never assigned values.

CAUSE

This is a bug in version 5.5 of the C51 compiler. See below for more information.

RESOLUTION

If you wish to enter lines of text, then the Measure example program demontrates how to do this by using the getkey() function. The code is self-contained and can be found in the getline.c source file.

A similar method can be used to enter values, either parsing the input as it is entered or by entering a string and calling atoi() to convert to an integer.

MORE INFORMATION

SEE ALSO

Last Reviewed: Tuesday, June 8, 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.