Pelles C forum

C language => Beginner questions => Topic started by: twh_twh on June 06, 2012, 06:20:22 PM

Title: scanf() --return value
Post by: twh_twh on June 06, 2012, 06:20:22 PM
good = scanf("%d",&number);

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

good == 1

why???
Title: Re: scanf() --return value
Post by: CommonTater 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)
Title: Re: scanf() --return value
Post by: twh_twh on June 07, 2012, 02:46:44 AM
thanks~~~I see...