Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can you check if it is right? my code is below. I just need to check if I am doing it right since I do

Can you check if it is right? my code is below. I just need to check if I am doing it right since I do not know how to compile. Please provide screenshot. I will make sure to thumbs up. Thank you!

#include #include void conversion(char *words, char *phoneNo) { int amt; int result; for(amt=0; words[amt]!='\0'; amt++) { char ch=words[amt]; if ('A' <= ch && ch <= 'C') // 50= number 2 in ascii result = 50; if ('D' <= ch && ch <= 'F') // 51= number 3 in ascii result = 51; if ('G' <= ch && ch <= 'I') // 52= number 4 in ascii and so forth result= 52; if ('J' <= ch && ch <= 'L') result = 53; if ('M' <= ch && ch <= 'O') result =54; if ('P' <= ch && ch <= 'S') result = 55; if ('T' <= ch && ch <= 'V') result = 56; if ('W' <= ch &&ch <= 'Y') // 57= number 9 in ascii result = 57; //puts the ascii number in the position in array phoneNo[amt] = result; } // adds null terminator to last position in array phoneNo[amt]='\0'; } int main() { FILE *read,*write; char words[8]; char phoneNo[8];

//reads phone_list.txt read = fopen("phone_list.txt", "r");

//creates phone_list.txt.cvt in writing mode write = fopen("phone_list.txt.cvt", "w"); if (read == NULL) printf("No file"); else { // while loop until end of file is reached while (!feof(read)) { // scans from read, in string format, and into words fscanf(read, "%s",words);

//calls the conversion function conversion(words,phoneNo); // prints from write pointer and prints phone number fprintf(write,"%s ",phoneNo); } } /* closing Input */ fclose(read); /* closing Output */ fclose(write);

//terminates return 0; }

phone_list.txt is the following:

TAKEOUT HAIRCUT THEBOSS BEERCAN PETCARE CARWASH MATHHLP ABAGAIL GROOMER CLEANER DAYCARE AIRPORT NUMBERS ROSELYN LETTERS MUSEUMS PROGRAM RUDOLPH LYNDSAY

and the output is supposed to be:

echo 'Expected:' echo 'Enter file name: phone_list.txt' echo 'Output file name: phone_list.txt.cvt' echo '8253688' echo '4247288' echo '8432677' echo '2337226' echo '7382273' echo '2279274' echo '6284457' echo '2224245' echo '4766637' echo '2532637' echo '3292273' echo '2477678' echo '6862377' echo '7673596' echo '5388377' echo '6873867' echo '7764726' echo '7836574'

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Which products should be restocked?

Answered: 1 week ago

Question

Analyse the process of new product of development.

Answered: 1 week ago

Question

Define Trade Mark.

Answered: 1 week ago