Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Standard telephone keypads contain the digits 0 through 9. The numbers 2 through

ID: 3681994 • Letter: S

Question

Standard telephone keypads contain the digits 0 through 9. The numbers 2 through 9 each have three letters associated with them, as is indicated by the following table:

Write a program that translate seven-letter words in a file to their corresponding phone numbers

1. Name your program phone_numbers.c

2. The program reads the content of the file and translate the seven-letter words into their corresponding phone numbers, then writes the phone numbers to a file with the same name but an added extension of .cvt. For example, if the original file name is phone_list.txt, then the corresponding phone numbers will be stored in a file named phone_list.txt.cvt. Assume the file name is no more than 100 characters.

Enter the file name: phone_list.txt

Output file name: phone_list.txt.cvt

3. The program should include the following function:

void translate(char *word, char *phone_number);

The function expects word to point to a string containing the seven-letter words to be translated; phone_number represents the pointer pointing to the string storing the phone number. For example, if the word is TAKEOUT, the function will store 8253688 pointed by phone_number.

phone_list.txt

TAKEOUT

HAIRCUT

THEBOSS

BEERCAN

PETCARE

CARWASH

MATHHLP

ABAGAIL

GROOMER

CLEANER

DAYCARE

AIRPORT

NUMBERS

Digit Letter Digit Letter 2 A B C 6 M N O 3 D E F 7 P R S 4 G H I 8 T U V 5 J K L 9 W X Y

Explanation / Answer

#include<stdio.h>
#include<stdlib.h>

void translate(char *word, char *phone_number);

char const charToDigitMap[] = {'2','2','2','3','3','3','4','4','4','5','5','5','6','6','6',
                                   '7','','7','7','8','8','8','9','9','9',''};

int main(){
                                  
   FILE *reads,*writes;
  
    reads=fopen("phone_list.txt", "r");
    writes=fopen("phone_list.txt.cvt", "w");
  
    if (reads==NULL) {
        perror("Error");
        return 1;
    }
    // declaring word and phone array
   char word[8];
   char phoneNumber[8];
  
   while(!feof(reads)) {
       // reading word from file    
        fscanf(reads, "%s", word);
        // translating word into phone number
        translate(word, phoneNumber);
        // writing phone number to file
        fprintf(writes,"%s ", phoneNumber);
   }
  
   printf("Data has successfilly writen to file ");
    fclose(reads);
    fclose(writes);
   return 0;
}

void translate(char *word, char *phone_number){
       int i;
       i=0;
       while(i<7){
           int j = word[i] - 65;
           phone_number[i] = charToDigitMap[j];
           i++;
       }
}


/*

Code Run Sample:

Input file name : phone_list.txt

Content of input file:

TAKEOUT
HAIRCUT
THEBOSS
BEERCAN
PETCARE
CARWASH
MATHHLP
GROOMER


Output filr: phone_list.txt.cvt

content of output file after running this program:

8253688
4247288
8432677
2337226
7382273
2279274
6284457
4766637
4766637

Note: input file and program should be in same folder.

*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote