Question
write a program in c language according to the instruction below. Please write it by using following instruction and function-prototype. Topics: User defined functions, character
write a program in c language according to the instruction below. Please write it by using following instruction and function-prototype.
Topics: User defined functions, character arrays, C style string member functions.
Synopsis:You will write an interactive C program that will allow a user to play the Hangman game.
Step by step:
Sample Output:
WELCOME TO HANGMAN!
Please read the following instructions before you play.
- You will be presented with a word to be guessed
- Guess letters one at a time
- You can have up to six incorrect letter guesses
- You can only guess the word when you have made a correct letter guess
- The game will be OVER when you have guessed the word correctly
Or when you have guessed letters incorrectly SIX times.
HAVE FUN!
Here are the letters guessed so far:
*********
Guess a letter: n
-------------------------------
The letter was in the word, you can now guess the word:
*N*******
Guess the word: answering
That is not the correct word
Here are the letters guessed so far: N
*N*******
Guess a letter: w
The letter was not in the word, the value of wrongGuesses is now 1
Here are the letters guessed so far: NW
*N*******
Guess a letter
: e
-------------------------------
The letter was in the word, you can now guess the word:
*N**E****
Guess the word: understand
That is not the correct word
Here are the letters guessed so far: NWE
*N**E****
Guess a letter: u
---------------------
----------
The letter was in the word, you can now guess the word:
UN**E****
Guess the word: universal
You won that round, congratuations!
Would you like to play another round (y or n)? y
Here are the letters guessed so far:
********
Guess a letter: r
-------------------------------
The letter was in the word, you can now guess the word:
*******R
Guess the word: forever
That is not the correct word
Here are the letters guessed so far: R
*******R
Guess a letter: e
--------------
-----------------
The letter was in the word, you can now guess the word:
E****EER
Guess the word: engineer
You won that round, congratuations!
Would you like to play another round (y or n)? y
Here are the letters guessed so far:
*****
Guess a letter
: o
The letter was not in the word, the value of wrongGuesses is now 1
Here are the letters guessed so far: O
*****
Guess a letter: p
The letter was not in the word, the value of wrongGuesses is now 2
Here are the letters guessed so far: OP
*****
Guess a letter: r
-------------------------------
The letter was in the word, you can now guess the word:
R***R
Guess the word: rover
That is not the correct word
Here are the letters guessed so far: OPR
R***R
Guess a letter: i
The letter was not
in the word, the value of wrongGuesses is now 3
Here are the letters guessed so far: OPRI
R***R
Guess a letter: e
The letter was not in the word, the value of wrongGuesses is now 4
Here are the letters guessed so far: OPRIE
R***R
Guess a letter: u
The letter was not in the word, the value of wrongGuesses is now 5
Here are the letters guessed so far: OPRIEU
R***R
Guess a letter: x
The letter was not in the word, the value of wrongGuesses is now 6
You did not win this round, the solution was
RADAR
Would you like to play another round (y or n)? n
Press any key to continue...........
The word.txt file below.
word.txt:
universal
engineer
radar
Trouble
apple
KEYS
extra
kind
Function Proto-type:
//this function provides instructions to the user on how to play the game
void HangmanRules();
//this function asks the user if they want to play another game (y or n)
void PlayAgain(char *againPtr);
//this function runs one game.
//input: character from the file, void return type
//all other functions to Play one round of a game
//are called from within the PlayOneGame function
void PlayOneGame(char solution[]);
//this function changes a character array to all uppercase letters
void UpperCaseWord(char word[]);
//this function creates the starword array
void CreateStarword(char starword[], int length);
//this function gets the users guess letter and adds it to the lettersGuessed array
//returns the letter entered by the user
char GetTheLetterGuess(char lettersGuessed[], int *numPtr);
//this function replaces any asterik in the starword with the current character enteed by the user
int ReplaceStars(char solution[], char starword[], char letter);
//this function gets the guess word,
//compares the solution and the guess word
//tells the user if they have won and returns a 1
//otherwise it returns a 0
int DidYouWin(char solution[]);
How to play the game Allow the user to guess letters one character at a time . At every stage of the game, the user should be able to view the current state of the If a letter is correctly guessed the player is notified and the letter appears in its proper word in progress" (star word) and the list of "guessed letters location in the "star word" array If a letter is not correct, the number of guesses is increased In ALL cases, the guessed letter should be added to the array for "guessed letters The user is allowed up to 6 incorrect guesses .The round of the game will end when the user has either guessed the word correctly or has made 6 incorrect letter guesses If the player guesses the word correctly, the player is notified that they have won and the correct word is displayed If the player does not get the correct word, the player is notified that they have lost and the correct word is displayed When the game is over, the user should be allowed to play again without having to execute the program again. (The player will play again with the next word in the file) Instructions . You will read the word to be guessed from a file "words.txt" which should contain upper and lower case words You will use 4 character arrays . one for the word to be guessed (which comes from the input file) o one for the star word" (same length as the word to be guessed) o one for all of the guessed letters o one for the "user's guess - remember to add the NULL character10 . remember to add the NULL character 10 Declare any additional variables needed . At the beginning of each game word to be guessed array start with an empty string Read a word from the file and store it in the word to be guessed array word in progress array should be adjusted to the correct length (that is the same size as the word read from the file but consists only of (asterisks) in the beginning (star word) guessed letters array should be empty - a character is added with each guessStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started