C Tutorial/Data Type/int Conversion
The atoi() function: read numeric values from the keyboard
The atoi() function converts a string into an integer value.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int age;
char years[8];
printf("Age:");
gets(years);
age=atoi(years);
printf("Age was %d years old.\n",age);
return(0);
}
Age:1 Age was 1 years old.