I still cannot figure out how to make the game: keep track of previously guessed letters, so the user will not guess the same letter twice. |
Well, the user has up to 6 guesses, so you could store his guesses, as they come, into a char array of length 6. The user's first guess would go into the first slot. For every other guess, you'd check the array and see if the current guess is in there. If so, then you say the user already guessed that and ask for another letter. You would do this in a loop until they put a valid guess. Say it's the user's fifth guess, you would check the array from the first to the fourth slot. If the user didn't guess the same char as he did before, then the current char goes in the fifth slot.
Have a function that takes a char array and returns a char array of *'s of the same length as the original char array.
Have another function that takes a char and a char array, and checks to see if that char is in the char array.... |
I don't know if these are part of your requirements or if you're just thinking aloud or something, but for these char arrays, you would also have to pass in their length. Otherwise, the function would not know when to stop looking. You could also designate a character as a terminator, such as '0'. That way, you'd know when to stop the loop if a length was not given.
If you need to implement these functions for whatever reason, for the first one, you would need to somehow know the length of the array (either the length is passed in or use a terminator character). Once you know the length, you would need to dynamically allocate the char array and put an asterisk for every character. You would use dynamic allocation because the length of the array is not known at compile time.
The second one is pretty straightforward. Just loop through the array given the length or look for a terminator, and if the character is spotted, return true. Otherwise, return false.