PDA

View Full Version : scanf() Function in ANSI C



Phantom
Feb 11th, 2003, 10:55 PM
Hello,

I started programming in ANSI C on Christmas 2002. I was going through a book that I had gotten for Xmas, and the book didn't really explain the scanf() function too well (at least, what I got out of it didn't seem right). I was wondering if someone would be so kind as to 'splain it to me :)

my MSN is [email protected] ;)

garfield_101
Feb 25th, 2003, 11:59 AM
i dont know if ansi c is the same with c++, but if it is the same well an example would be:
a=b+c;
scanf("%d",&a);

wherein a is the sum of whatever values that b and c holds? the &a points to the value contain within the address of a. scanf accepts data only of decimal type to the address of a.

djdante97
Mar 3rd, 2003, 08:58 PM
scanf work similar to printf... first you specify the format string, then the variables that you want to read in to..

ex: scanf("%d %f %c", &anInteger, &aFloat, %aChar)

(i can't remember if there needs to be commas between the &d, &f, and &c)

Cheers,
Dan

Phantom
Mar 3rd, 2003, 09:11 PM
I understand now :)

And no, no need for commas :)