![]() |
Reading in a number from the userThough you were introduced to pointers this week, you have not dealt yet with arrays or strings in C. This makes user input a bit more challenging. Here's a bit of help: #include <stdio.h> void main() { char c[10]; int num = 0; printf("Enter a number: "); fgets(c, 10, stdin); num = atoi(c); printf("%.2f\n", num/1.0); }
You can find descriptions of the
Basically, this little program gets a number from the user and prints it back to the screen as a float (with no error checking). To do this, it creates a character array |
~ztomasze Index :
TA Details : ICS212 : Input Help http://www2.hawaii.edu/~ztomasze |
Last Edited: 24 Aug 2005 ©2005 by Z. Tomaszewski. |