help me solve this question..


Write a program for an animal guessing game. The program will randomly select a word inside a
text file containing a collection of animal names. The game begins by allowing the user to enter
a character, and continually guess a character at a time to solve it.

For example:

- If the character is inside is in the word but hide unguessed characters (e.g. The word is


  • [color=Blue]
    This is what you need to do:

    1. Open the text file (use function fopen)
    2. Load all words from the file into an array (use function fgets to read lines in the file. Each line has an animal name). Since file can be large - you need dynamic allocation of memory, so you need to use new (for C++) or malloc (for C). To allocate the string use function strdup.
    3. Once all words are loaded - use fclose to close the file. Also, now you know how many words you have.
    4. Use srand to initialize the random number generator.
    5. Use function rand to get the random index in your array of words.

    6. Now, begin a loop of asking user to input a letter and decide if that letter is present in the word.

    print your word character by character - comparing the word letter with inputted letter. If they match: print the letter, otherwise print '-'. If nothing matched during print - print a message about a miss and count that miss. If the miss count reaches 10 then game ends.
    If during print no '-' was printed - that means all letters was found out! He/She wins!!

    If any '-' was printed and miss count is less than 10 then go back to the loop beginning to ask for more letters. If a letter was a miss - print all missed letters under the main printout, so it will be easier not to guess these letter again.

    Big task.

    This will help:
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


In this Discussion