Hi am having trouble with the arrays of letters and hyphens in my hangman project
for example:
#include<stdio.h>
#include<stdlib.h>
#define letters 80
main()
{
char word[letters] = {'t','r', 'i', 'c', 'k'};
char spaces[letters] = {'-', '-', '-', '-', '-'};
char used[USED] = {' ', ' ',' ',' ',' ',' ',' '};
int startmenu, PlayGame, ExitGame;
int lives = 6;
int i;
int j = 0;
int correct;
char symb;
int length = 5;
printf("Lets PLay Hangman!");
printf("\n1. Play game\n0. Exit");
scanf("%d",&startmenu);
switch( startmenu )
{
case 1:
{
for(i=0; i < length ; i++)
{
word[length]=0;
}
word[length] = 0;
printf("%c", spaces);
while ((lives>0) && (j < length))
{
correct = 0;
printf("Please enter a letter: ");
do
{
scanf("%c", &symb);
if((symb > 32) && ((symb < 97) || (symb > 122)))
{
printf("Invalid character\nEnter a letter: ");
}
}while((symb < 97) || (symb > 122));
for(i=0; i<length; i++)
{
if(symb == word[i])
{
printf("This character has been used already\n");
break;
}
}
if(i == length)
{
for(i=0;i < length;i++)
{
if(symb == word[i])
{
word[i] = symb;
correct = 1;
printf("That was correct:D you have %i lives left.\n");
printf("You have %s\n",spaces);
}
}
if(correct == 0)
{
lives--;
if(lives > 0)
{
printf("Sorry that was not right! %i lives left.\n",lives);
}
else
{
printf("Sorry You lost! :(\n");
}
printf("You have %s\n",word);
}
}
}
}
case 0:
{
return 0;
}
}
getchar();
getchar();
}
That is my code so far. I know there are a good few issues in there that need to be sorted but the main problem I was having was to get my guess to replace the hyphen.