Read a string and convert it into a numeric value by the atoi() function. - C Language Basics

C examples for Language Basics:scanf

Description

Read a string and convert it into a numeric value by the atoi() function.

Demo Code

#include <stdio.h>
#include <stdlib.h>
int main()// w w w  .  j a va  2 s .c om
{
   int age;
   char years[8];
   printf("How old was James?");
   gets_s(years);
   age=atoi(years);
   printf("James was %d years old.\n",age);
   return(0);
}

Result


Related Tutorials