C examples for Language Basics:scanf
Read a string and convert it into a numeric value by the atoi() function.
#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); }