• API
• FAQ
• Tools
• Archive
daily pastebin goal
12%
SHARE
TWEET

# Untitled

a guest Jan 18th, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. //Homework 2 Problem 1
2. //Found on Page 157 of C Programing a Modern Approach
3.
4. #include <stdio.h>
5. #include <string.h>
6.
7. int main()
8. {
9.         char ph_number[15];
10.         char ph_conv[15];
11.         int cntr = 0;
12.         printf("Enter a text phone number (eg. 1-800-ABC-DEFG) press enter when finished entering the phone number\n");
13.         do
14.         {
15.                 scanf("%1c", &ph_number[cntr]);
16.                 ++cntr;
17.         }while(ph_number[cntr-1] != '\n');
18.
19.         for(cntr=0; ph_number[cntr]; cntr++)
20.         {
21.                 printf("%c, %d, ", ph_number[cntr], (int)ph_number[cntr]);
22.         }
23.
24.         printf("\n");
25.         cntr = 0;
26.
27.     //Continually returns 2 for all values for unknown reason
28.     do
29.         {
30.                 if(65 <= (int)ph_number[cntr] <= 67 || 97 <= (int)ph_number[cntr] <= 99){
31.                         ph_conv[cntr] = '2';}
32.                 else if(67 < (int)ph_number[cntr] <= 70 || 99 < (int)ph_number[cntr] <= 102){
33.                         ph_conv[cntr] = '3';}
34.                 else if(70 < (int)ph_number[cntr] <= 73 || 102 < (int)ph_number[cntr] <= 105){
35.                         ph_conv[cntr] = '4';}
36.                 else if(73 < (int)ph_number[cntr] <= 76 || 105 < (int)ph_number[cntr] <= 108){
37.                         ph_conv[cntr] = '5';}
38.                 else if(76 < (int)ph_number[cntr] <= 79 || 108 < (int)ph_number[cntr] <= 111){
39.                         ph_conv[cntr] = '6';}
40.             else if(79 < (int)ph_number[cntr] <= 83 || 111 < (int)ph_number[cntr] <= 115){
41.                 ph_conv[cntr] = '7';}
42.             else if(83 < (int)ph_number[cntr] <= 86 || 116 < (int)ph_number[cntr] <= 118){
43.                 ph_conv[cntr] = '8';}
44.             else if(87 < (int)ph_number[cntr] <= 90 || 118 < (int)ph_number[cntr] <= 122){
45.                     ph_conv[cntr] = '9';}
46.                 else{ ph_conv[cntr] = ph_number[cntr];}
47.                 ++cntr;
48.         }while(ph_number[cntr-1] != '\n');
49.
50.         cntr = 0;
51.         do
52.         {
53.                 printf("%c", (char)ph_conv[cntr]);
54.                 ++cntr;
55.         }while(ph_conv[cntr-1]);
56.
57.         printf("\n");
58.         return(0);
59. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top