02-23-2003, 07:31 AM
I have had trouble understanding the scanf() function in C. Basically, what is it? What does it do? When is it helpful/when do you use it? If someone can help me out, it'd be coo :)
02-23-2003, 07:48 PM
Hi... I remember when I started to code in C... I ran across the same thing ! :D
ok.. so without any further delays... scanf() is a function that is used to take input from the stdin. it takes in a format string of the type "%d" (similar to printf() format string) and the reference to variables that will hold the value e.g. &iVal
so if I were to scan an integer .. I would do:
printf("Enter The Value Please: ");
:D Hope that helps ...
02-23-2003, 09:52 PM
Couldn't you do:
printf("Enter an integer please:\n");
i = getc(stdin);
and get the same result?
02-24-2003, 01:49 AM
Nopes... that would return a character from the standard input only which will be implicitly type casted to int resulting an ASCII value only... which is probably not what you would want in most cases :)
Using scanf() with format strings allow you to take any kind of input provided u give in the right format string...
02-24-2003, 02:38 AM
Glad to be of any assitance :)