Hey all,
I'm a newbie and I'm learning C language (reading book for Dummies), I have no one else to ask, because I'm too shy, and sorry if this is too dumb or a third grade question, but I need to know if I have understood the atoi function right or am I missing something, because it just seems weird. I have been configuring the code for the fifth time and I'm just curious.
As I understand, then atoi is for reading value strings from a keyboard (is that right)? Because we can't read values, using int integral through something simply as this:
Code:
int deer_age;
printf("How old is the deer?");
gets(deer_age);
printf("Deer is %d years old",deer);
, because it just won't work, instead we have to give an integer his years and then simply print it out. And of course there's not way giving an char variable his age either, cuz it won't work that way, so we use the atoi function to print out his years, which goes, of course, like this:
Code:
int deer_age;
char deer[20];
printf("How old is the deer?");
gets(deer);
deer_age=atoi(deer);
printf("Deer is %d years old",deer_age);
Have I got it right? Should I stop worry.
Thanks for the replies. I know this seems a bit awkward.