PDA

View Full Version : scanf() Function in ANSI C



Phantom
02-11-2003, 11: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 phantasmagoria@l33ad.com ;)

garfield_101
02-25-2003, 12:59 PM
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
03-03-2003, 09: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
03-03-2003, 10:11 PM
I understand now :)

And no, no need for commas :)