Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Homework 2 Problem 1
- //Found on Page 157 of C Programing a Modern Approach
- #include <stdio.h>
- #include <string.h>
- int main()
- {
- char ph_number[15];
- char ph_conv[15];
- int cntr = 0;
- printf("Enter a text phone number (eg. 1-800-ABC-DEFG) press enter when finished entering the phone number\n");
- do
- {
- scanf("%1c", &ph_number[cntr]);
- ++cntr;
- }while(ph_number[cntr-1] != '\n');
- for(cntr=0; ph_number[cntr]; cntr++)
- {
- printf("%c, %d, ", ph_number[cntr], (int)ph_number[cntr]);
- }
- printf("\n");
- cntr = 0;
- //Continually returns 2 for all values for unknown reason
- do
- {
- if(65 <= (int)ph_number[cntr] <= 67 || 97 <= (int)ph_number[cntr] <= 99){
- ph_conv[cntr] = '2';}
- else if(67 < (int)ph_number[cntr] <= 70 || 99 < (int)ph_number[cntr] <= 102){
- ph_conv[cntr] = '3';}
- else if(70 < (int)ph_number[cntr] <= 73 || 102 < (int)ph_number[cntr] <= 105){
- ph_conv[cntr] = '4';}
- else if(73 < (int)ph_number[cntr] <= 76 || 105 < (int)ph_number[cntr] <= 108){
- ph_conv[cntr] = '5';}
- else if(76 < (int)ph_number[cntr] <= 79 || 108 < (int)ph_number[cntr] <= 111){
- ph_conv[cntr] = '6';}
- else if(79 < (int)ph_number[cntr] <= 83 || 111 < (int)ph_number[cntr] <= 115){
- ph_conv[cntr] = '7';}
- else if(83 < (int)ph_number[cntr] <= 86 || 116 < (int)ph_number[cntr] <= 118){
- ph_conv[cntr] = '8';}
- else if(87 < (int)ph_number[cntr] <= 90 || 118 < (int)ph_number[cntr] <= 122){
- ph_conv[cntr] = '9';}
- else{ ph_conv[cntr] = ph_number[cntr];}
- ++cntr;
- }while(ph_number[cntr-1] != '\n');
- cntr = 0;
- do
- {
- printf("%c", (char)ph_conv[cntr]);
- ++cntr;
- }while(ph_conv[cntr-1]);
- printf("\n");
- return(0);
- }
Add Comment
Please, Sign In to add comment