Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!