Look at the following code and the output:
Code:
#include <stdio.h> // For printf() and scanf() functions
#include <stdlib.h> // For atoi() function
int main(void)
{
char ary[64] = "123"; // Initialize all local variables
int val = 0;
double dval = 0.0;
printf("The initial string in the array: %s\n\n", ary);
val = atoi(ary);
printf("The converted string to an int: %d\n\n", val);
printf("Please enter a double: ");
scanf("%lf", &dval); // The '&' is needed here. scanf() needs an address
printf("The double value entered is: %lf\n\n", dval);
printf("Please enter a name: ");
scanf("%s", ary); // But not here. ary is an address
printf("The name entered was: %s\n", ary);
return 0;
}
Output:
Code:
The initial string in the array: 123
The converted string to an int: 123
Please enter a double: 3.14
The double value entered is: 3.140000
Please enter a name: John
The name entered was: John
Is this what you are trying to do?
Normally, I would use fgets() to enter strings, but start with scanf().
I can't teach you the entire language here. You need to get a book and STUDY the language yourself!!!