Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

11.13 (Telephone-Number Word Generator) Standard telephone keypads contain the digits 09. The numbers 29 each have three letters associated with them, as is indicated by

11.13 (Telephone-Number Word Generator) Standard telephone keypads contain the digits 09. The numbers 29 each have three letters associated with them, as is indicated by the following table: 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 Many people find it difficult to memorize phone numbers, so they use the correspondence between digits and letters to develop seven-letter words that correspond to their phone numbers. For example, a person whose telephone number is 686-2377 might use the correspondence indicated in the above table to develop the seven-letter word NUMBERS. Businesses frequently attempt to get telephone numbers that are easy for their clients to remember. If a business can advertise a simple word for its customers to dial, then, no doubt, the business will receive a few more calls. Each seven-letter word corresponds to exactly one seven-digit telephone number. The restaurant wishing to increase its take-home business could surely do so with the number 825-3688 (i.e., TAKEOUT). Each seven-digit phone number corresponds to many separate seven-letter words. Unfortunately, most of these represent unrecognizable juxtapositions of letters. Its possible, however, that the owner of a barber shop would be pleased to know that the shops telephone number, 424-7288, corresponds to HAIRCUT. The owner of a liquor store would, no doubt, be delighted to find that the stores telephone number, 233-7226, corresponds to BEERCAN. A veterinarian with the phone number 738-2273 would be pleased to know that the number corresponds to the letters PETCARE. Write a C program that, given a seven-digit number, writes to a file every possible seven-letter word corresponding to that number. There are 2187 (3 to the seventh power) such words. Avoid phone numbers with the digits 0 and 1.

This is what I have:

#include

//User generated function

void wordGenerator(int telephoneNumber[]);

int main()

{

//counter for loop

int telephoneLoop = 0;

//array to store phone number

int phone_Number[7] = { 0 };

//prompt user to enter phone number one digit at a time

printf("Enter the 7 digit phone number, using only the digits 2 to 9: ");

//Loops seven times to receive phone number

while (telephoneLoop

{

scanf("%d", &phone_Number[telephoneLoop]);

//Check if number is between 2 and 9

while (phone_Number[telephoneLoop] 9)

{

printf(" Error: Invalid phone number entered. Please try again: ");

scanf("%d", &phone_Number[telephoneLoop]);

}// End loop

telephoneLoop++;

}// end loop

// Call function to generate words out of phone numbers

wordGenerator(phone_Number);

return 0;

}// End main

void wordGenerator(int telephoneNumber[])

{

// counter for loop

int telephoneLoop;

//Loops to take 1st - 7th digit of phone number

int telephoneLoop1;

int telephoneLoop2;

int telephoneLoop3;

int telephoneLoop4;

int telephoneLoop5;

int telephoneLoop6;

int telephoneLoop7;

// file pointer

FILE *tpnWg;

// Letters that correspond to each digit

char *number_Letters[10] = { "", "", "ABC", "DEF","GHI","JKL","MNO","PQRS","TUV","WXY" };

//Opens file in write mode

if ((tpnWg = fopen("telephone.out", "v")) == NULL)

{

printf("File cannot be opened. ");

}// End if

else

{

//display possible word combos

//loop to replace first digit

for (telephoneLoop1 = 0; telephoneLoop1

{

// loop to replace 2nd digit

for (telephoneLoop2 = 0; telephoneLoop2

{

//Loop for 3rd digit

for (telephoneLoop3 = 0; telephoneLoop3

{

//Loop for 4th digit

for (telephoneLoop4 = 0; telephoneLoop4

{

//Loop for 5th digit

for (telephoneLoop5 = 0; telephoneLoop5

{

//Loop for 6th digit

for (telephoneLoop6 = 0; telephoneLoop6

{

//Loop for 7th digit

for (telephoneLoop7 = 0; telephoneLoop7

{

fprintf(tpnWg, "%c%c%c%c%c%c%c ", number_Letters[telephoneNumber[0]][telephoneLoop1], number_Letters[telephoneNumber[1]][telephoneLoop2], number_Letters[telephoneNumber[2]][telephoneLoop3], number_Letters[telephoneNumber[3]][telephoneLoop4], number_Letters[telephoneNumber[4]][telephoneLoop5], number_Letters[telephoneNumber[5]][telephoneLoop6], number_Letters[telephoneNumber[6]][telephoneLoop7]);

}//End for

}//End for

}//End for

}//End for

}//End for

}//End for

}//End for

//Display phone number

fprintf(tpnWg, " Phone number is: ");

for (telephoneLoop = 0; telephoneLoop

{

// to insert dash

if (telephoneLoop == 3)

{

fprintf(tpnWg, "-");

}// End if

fprintf(tpnWg, "%d", telephoneNumber[telephoneLoop]);

}// End for loop

}// End Else

// file pointer closed

fclose(tpnWg);

}

I do not want a completely different code I only want help fixing what I have, but when I run the program this is what happens.

image text in transcribed

SCAWINDOWSlsystem321cmd.exe Enter the 7 digit phone number, using only the digits 2 to 9: 6 ens. Microsoft Visual CRuntime Library Debug Assertion Failed! Program: ...pter 11 ProgramlDebugl Kirstin Richards Chapter 11 Program.exe File: minkernecrtslucrtlinclcorecrt internal_stdio.h Line: 618 Expression: CInvalid file open mode", 0) For information on how your program can cause an assertion failure, see the Visual C++ documentation on asserts. (Press Retry to debug the application) Abort Retry

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

Database Security

Authors: Alfred Basta, Melissa Zgola

1st Edition

1435453905, 978-1435453906

More Books

Students also viewed these Databases questions