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: 3682285 • 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: Digit Letter A BC 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

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

//function to translate words to phone nunbers
void translate(char *word, char *phone_number){
char ch;
int i;
for(i=0;word[i]!='';i++)
{
ch=word[i];
if ('a' <= ch && ch <= 'c')
phone_number[i] = '2';
if ('d' <= ch && ch <= 'f')
phone_number[i] = '3';
if ('g' <= ch && ch <= 'i')
phone_number[i] = '4';
if ('j' <= ch && ch <= 'l')
phone_number[i] = '5';
if ('m' <= ch && ch <= 'o')
phone_number[i] = '6';
if ('p' <= ch && ch <= 's')
phone_number[i] = '7';
if ('t' <= ch && ch <= 'v')
phone_number[i] = '8';
if ('w' <= ch && ch <= 'y')
phone_number[i] = '9';
}
}

int main()
{
//char arrays declared
char c[1000];
char phone_number[1000];
FILE *fptr, *fptr1;
//opening file to read
if ((fptr=fopen("phone_numbers.txt","r"))==NULL){
printf("File cannot opened");
exit(1);   
}
//opening file to write
if ((fptr1=fopen("phone_numbers.txt.cwt","w"))==NULL){
printf("File cannot opened");
exit(1);   
}
//reading file line by line
fscanf(fptr,"%[^ ]",c);
//calling function
translate(c,&phone_number);
//writing resultant word to file
fprintf(fptr,"%s",phone_number);
fclose(fptr);
return 0;
}

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