C Tutorial/Data Type/int Conversion

Материал из C\C++ эксперт
Перейти к: навигация, поиск

The atoi() function: read numeric values from the keyboard

The atoi() function converts a string into an integer value.


<source lang="cpp">#include <stdio.h>

  1. 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);

}</source>

Age:1
      Age was 1 years old.