Hey Guys,
This is a crazy problem. I'm doing some testing to make sure I understand how to use the pointers to arrays before I finish the code. If I run the code and type in 00 or 11 it works correctly or at least appears to. If you type in 10, the result is 'twenty'. It's crazy!
Code:
//http://knking.com/books/c2/answers/c13.html
#include <stdio.h>
int main(){
char *digOne[]={"twenty", "thirty", "fourty", "fifty", "sixty", "seventy", "eighty", "ninety"};
char *digTwo[]={"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
char *digThree[]={"ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"};
char num[2];
printf("Enter a two-digit number: ");
scanf("%s", num);
if(num[0]==48&&num[1]==48){ //if 00 is entered
printf("%s",digTwo[0]); //prints zero
}
else if(num[0]==49&&num[1]==48){ //if 10 is entered
printf("%s",digThree[0]); //prints twenty? CRAZY!!!
}
else if(num[0]==49&&num[1]==49){ //if 11 is entered
printf("%s",digThree[1]); //prints eleven
}
return 0;
}
If I comment out
Code:
//char *digOne[]={ ...
and then run the program, if I enter 10 again, it prints zero. What The Heck is wrong with what I wrote or with my head?