im having trouble understanding this function i mean what is the purpose of it. if i wanted an integer i would ask for one. it makes no sense to me that if u want an integer you would ask for a string and then convert it into an integer i mean whats the point eg
why could i not just do this :Code:#include <stdio.h> #include <stdlib.h> int main() { int age; char years[8]; printf(“How old was Methuselah?”); gets(years); age=atoi(years); printf(“Methuselah was %d years old.\n”,age); return(0); }
Code:#include <stdio.h> #include <stdlib.h> int main() { int age; printf(“How old was Methuselah?”); scanf("%d",age); printf(“Methuselah was %d years old.\n”,age); return(0); }