#include <stdio.h>
#include<string.h>
#include <unistd.h>
#include <stdlib.h>
#include <time.h>
int main(){
int lives = 7;
char words[11][21] = {"wibble", "wobble", "hello","world","christmas","holiday","happy","cake","funny","cracker"};
srand(time(NULL));
int indexw = rand()%10;
int len = strlen(words[indexw]);
char b[21];
for (int i = 0; i<len; i++){
b[i] = words[indexw][i];
}
b[len] = '\0';
char guessed[21] = "????????????????????";
int done = 0;
while (! done){
char show[41] = "";
char add[3];
char guess;
for (int x = 0; x< len; x++){
if (guessed[x]!='?'){
add[0]= guessed[x];
}
else{
add[0] = '_';
}
add[1] = ' ';
add[2] = '\0';
strcat(show, add);}
printf("\n%s\n", show);
printf("guess a new letter:");
scanf(" %c", &guess);
done = 1;
int found = 0;
for (int i=0; i<len; i++){
if (b[i]==guess){
guessed[i] = b[i];
found = 1;
}
if (guessed[i]=='?'){
done = 0;
}
}
if (found){
printf("\ncorrect!\n");
}
else{
lives = lives-1;
printf("\nincorrect\n");
if (lives == 0){
printf("Shame!\nyou ran out of lives, the word was %s.", b);
done = 1;
}else{
printf("you only have %d lives left", lives);
}}
sleep(1);
}
return 0;
}