Ask your own question, for FREE!
Computer Science 12 Online
OpenStudy (anonymous):

C Program Help! Easy question! .. hard for me. please help! Objective: Modify the scan.c example from my notes so that it reads in a double and a long instead of a float and an int. Also, initialize the two variables so that they do not contain "junk" at the beginning of the program Original: See image ->>http://imgur.com/iW9m7ye What I have tried so far: See image ->> http://imgur.com/K9MBGtT Xcode is attempting to help me, but I think its confused ... or maybe I am. I understand that a Double is %f and Long Double is %Lf

OpenStudy (rsmith6559):

I got a clean compile and it ran properly with this code: ``` #include <stdio.h> int main() { double x; puts( "Enter a float: " ); scanf( "%lf", &x ); printf( "X == %f\n", x); return( 0 ); } ```

OpenStudy (anonymous):

Xcode is trying to warn you that you are using the float specifier instead of the "%d" int specifier. On another note, using scanf() is unsafe. Use a safer way to read the string into your program like fgets() and convert via scanf() or strtol()/strtod(). Example:

OpenStudy (anonymous):

The Example is in main.c attachment.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!