#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int init(char* word)
{
srand(time(NULL));
int randomIndex = rand() % 50;
const char* words[50] = {
"array", "auto", "break", "case", "cast",
"character", "comment", "compiler", "constant", "continue",
"default", "double", "dynamic", "else", "enum",
"expression", "extern", "file", "float", "function",
"goto", "heap", "identifier", "library", "linker",
"long", "macro", "operand", "operator", "pointer",
"prototype", "recursion", "register", "return", "short",
"signed", "sizeof", "stack", "statement", "static",
"string", "struct", "switch", "typedef", "union",
"unsigned", "variable", "void", "volatile", "while"
};
strcpy(word, words[randomIndex]);
int lengthOfWord = strlen(words[randomIndex]);
return lengthOfWord;
}
void displayWord(char *word, int *guessedLetters, int length)
{
int i;
for (i = 0; i < length; i++ ){
if(guessedLetters[word[i] - 97] == 1){
printf("%c", word[i]);
}else{
printf("-");
}
}
printf("\n\n");
}
int main(int argc, char *argv[]){
char word[500];
int len;
int guessedLetters[26] = {
1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0
};
len = init(word);
printf("\nWord = %s", word);
printf("\nGuessed: ");
displayWord(word, guessedLetters, len);
return 0;
}