Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int main(int argc, const char * argv[])
- {
- char word[4], cont='y';
- int digit[4], length=0, i;
- while(cont=='y'){
- printf("please enter a word"); fflush(stdin); scanf("%s", word);
- length = strlen(word);
- if(length>4){ printf("please enter a word only 4 letters long\n"); return 0;}
- for(i=0;i<=4;i++){
- switch(word[i]){
- case 'a': case 'b': case 'c':
- digit[i]=2;
- break;
- case 'd': case 'e': case 'f':
- digit[i]=3;
- break;
- case 'g': case 'h': case 'i':
- digit[i]=4;
- break;
- case 'j': case 'k': case 'l':
- digit[i]=5;
- break;
- case 'm': case 'n': case 'o':
- digit[i]=6;
- break;
- case 'p': case 'q': case 'r': case 's':
- digit[i]=7;
- break;
- case 't': case 'u': case 'v':
- digit[i]=8;
- break;
- case 'w': case 'x': case'y': case 'z':
- digit[i]=9;
- break;
- }
- i++;
- }
- printf("The code that your word represents is %d%d%d%d\n", digit[0], digit[1], digit[2], digit[3]);
- printf("Would you like to enter another word? Enter 'y' to continue, 'n' to exit: ");
- fflush(stdin);
- scanf("%c", &cont);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement