NO

Author Topic: scanf() --return value  (Read 2358 times)

twh_twh

  • Guest
scanf() --return value
« on: June 06, 2012, 06:20:22 PM »
good = scanf("%d",&number);

--------------------------
my input a float 1.23

good == 1

why???

CommonTater

  • Guest
Re: scanf() --return value
« Reply #1 on: June 06, 2012, 06:32:17 PM »
Scanf returns the number of successful conversions...  it did one conversion...

However if you are entering floating point numbers you don't want to use %d ... you want %f in most cases.  Also your receptor variable has to be either a float or a double.  If it is not you will get the integer part of the number and the rest will be truncated.  Check the value of your number variable... you'll see.

(Put your text cursor on the highlighted word scanf in your source code and press F1 on your keyboard for full details)
« Last Edit: June 06, 2012, 06:34:37 PM by CommonTater »

twh_twh

  • Guest
Re: scanf() --return value
« Reply #2 on: June 07, 2012, 02:46:44 AM »
thanks~~~I see...