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

For mac Gcc Terminal . Please show output!. Standard telephone keypads contain t

ID: 3681448 • Letter: F

Question

For mac Gcc Terminal . Please show output!.

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: Digit Letter ABC DEF GHI JKL Digit 6 Letter MNO PRS TUV WXY 4 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.

Explanation / Answer

I have tested few words from your input. Let me know in case of any doubt.

#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++;
       }
}

/*

phone_list.txt

TAKEOUT
HAIRCUT
THEBOSS
BEERCAN
PETCARE
CARWASH
MATHHLP
GROOMER

phone_list.txt.cvt

8253688
4247288
8432677
2337226
7382273
2279274
6284457
4766637
4766637

*/