Need help with a Hangman program. It needs to allow an user to enter a word then let another user to guess the word. I think the error is in the Game function, where I am trying to copy the string entered by the first user to a new string, then find the length of the string, then replace the chars with '-', then user 2 is asked to enter a letter and that letter is compared to the original string.
Code:
#include <stdio.h>
#include <string.h>
void Game();
void DrawGallows(int place);
int main()
{
char PlayAgain = 'Y';
printf("-Hangman-\n\n");
while(PlayAgain == 'Y')
{
Game();
printf("\nDo you want to play again, Y or N? ");
scanf("%c", &PlayAgain);
}
printf("Thanks for Playing.\n");
return 0;
}
void Game()
{
int Size;
int Place = 1;
int Dash;
char Letter;
int Correct = 0;
char WordStr[80];
char WordCopy[80];
printf("Enter a word: ");
scanf("%s", WordStr);
strcopy(WordCopy,WordStr);
Size = strlen(WordCopy);
for(Dash = 0; Dash < Size; Dash++)
{
WordStr[Dash] = '-';
}
WordStr[Dash] = '\0';
while(Place!=6)
{
DrawGallows(Place);
printf("%s", WordStr);
print("Enter a letter :");
scanf("%c", &Letter);
for(Dash = 0; Dash < Size; Dash++)
{
if(WordCopy[Dash] == Letter)
{
WordCopy[Dash] = Letter;
Correct = 1;
printf("\nCorrect!\n");
if(strcmp(WordCopy,WordStr) == 0)
{
printf("\nWinner\n");
return;
}
}
}
if(Correct == 0)
{
printf("Wrong, Try Again");
Place++;
}
Correct = 0;
}
DrawGallows(Place);
printf("The word was: %s", WordStr);
}
void DrawGallows(int Place)
{
if(Place == 6)
{
printf("+----+ \n");
printf("| | \n");
printf("| O \n");
printf("| /|\\ \n");
printf("| / \\ \n");
printf("| Your Dead \n");
printf("=============\n\n");
}
else if(Place == 5)
{
printf("+----+ \n");
printf("| | \n");
printf("| O \n");
printf("| /|\\ \n");
printf("| \\ \n");
printf("| \n");
printf("=============\n\n");
}
else if(Place == 4)
{
printf("+----+ \n");
printf("| | \n");
printf("| O \n");
printf("| /|\\ \n");
printf("| \n");
printf("| \n");
printf("=============\n\n");
}
else if(Place == 3)
{
printf("+----+ \n");
printf("| | \n");
printf("| O \n");
printf("| /| \n");
printf("| \n");
printf("| \n");
printf("=============\n\n");
}
else if(Place == 2)
{
printf("+----+ \n");
printf("| | \n");
printf("| O \n");
printf("| | \n");
printf("| \n");
printf("| \n");
printf("=============\n\n");
}
else if(Place == 1)
{
printf("+----+ \n");
printf("| | \n");
printf("| \n");
printf("| \n");
printf("| \n");
printf("| \n");
printf("=============\n\n");
}
}