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.
2.6.int Conversion |
| 2.6.1. | The atoi() function: read numeric values from the keyboard |