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

MUST WORK IN C ENVIRONMENT The purpose of this exercise is to write the file pro

ID: 3614439 • Letter: M

Question

MUST WORK IN C ENVIRONMENT

The purpose of this exercise is to write the file processing andinitial stage of a hangman game. You will read words in from auser-specified file (hangman.dat) until EOF is reached, store themin a 2-dimensional array called "WordArray" and call a randomnumber generator to randomly choose one word from the WordArray touse for the next game. Fianlly, you will save the "Secret Word"into a filename provided by the user.

Specifications:
Ask the user for the name of the input file, save that name as astring, and "echo" the file name to the screen with an appropriatemessage.

Write a function called read_words that is passed the name ofthe input file. Read_words then reads in the words in the namedfile (up to a maximum of 50) and stores them in a 2-dimensionalarray called WordArray. This array will be passed back to main() asa parameter, along with the total number of words contained in thearray.

Write a function called get_word that takes three parameters: the2-dimensional WordArray (which has been filled with the words fromthe input file); a char array that will hold the word specificallychosen for this game, and the number of words in WordArray. Thisfunction will call a random number generator (see code below) thatwill provide a random number to select a word from WordArray forthe game. The chosen word is passed back to main() to be used toplay the game.

Write a function call get_random that calls the predefine functionrand() to generate a random number within the proper range and usesa return statement to return the random number. This functionshould be passed the number of words in WordArray. You may use thefollowing code to generate random number.

srand(23); //"seeds" the random number generator
return(rand() % num_words);

Requirements for main()

The main() function should print an introduction (perhaps the rulesfor the game of hangman), request the name of the data file, andcall read_words and get_word. It should then print out the totalnumber of words that were in the input file, and the word that wasselected. Finally, it should prompt the user for a filename andsave the chosen word to that file.

Use the preprocessor command #define to define the followingsymbolic global constants

MAX_GUESSES: This will store the maximum number of possible guessesfor someone playing the hangman game. (This will not exceed 26)

MAX_INCORRECT_GUESSES: This will store the maximum number ofpossible guesses for someone playing the hangman game. (This shouldbe 9)

MAX_WORD_LENGTH: This will store the maximum word length for anyhangman game word.
(Make sure it is large enough to cover all words provided in thedata file "Hangman.dat"

MAX_WORDS: This will store the maximum number of words to be readinto WordArray.
(This should not be greater than 50)

Hangman.dat contains following; (be sure that words on each lineremains as below)

vitreous omnivore tabernacle battalion
chronological ignoramus slantwise wergeld
importunate onomastic pasquinade tripalmitin
covariance emollient rogue syzygy incarnadine
kibosh batik frieze primogenitor zucchini
leprechaun splenomegaly ultrasonic meringue
cerulean lottery nucleotide paroxysm doubloon
chartreuse hookah eelworm crenulate jurisdiction
hymnal mediocre pollinate troubadour solstice
tumultuous ziggarut charisma truncate chicanery


Explanation / Answer

please rate - thanks any problems with it message me #include #include #define MAX_GUESSES 5 #define MAX_INCORRECT_GUESSES 9 #define MAX_WORD_LENGTH 15 #define MAX_WORDS 50 int read_words(char[],char[][]); void get_word(char[][],char[],int); int get_random(int); int main() { FILE *output; int i,count; char filename[20]; char WordArray[MAX_WORDS][MAX_WORD_LENGTH]; char word[MAX_WORD_LENGTH]; printf("This is the game of Hangman "); printf("Enter input file name: "); scanf("%s",&filename); printf("I will open %s ",filename); count=read_words(filename,WordArray); if(count==-999)     return 1; get_word(WordArray,word,count); printf("Enter output file name: "); scanf("%s",&filename); output= fopen(filename,"w"); if(output==NULL) {printf("Error opening Output File! ");     getch();     return 0; } fprintf(output,"%s ",word); fclose(output); getch(); } void get_word(char a[][MAX_WORD_LENGTH],char w[],int count) {int n,i; n=get_random(count); for(i=0;i
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