Have looked for a similar answer but nothing I try works.
Have an issue, I want to change the value of word
by calling the void function init()
but when I print the word it does not work.
Have spent way to many hours on this so any help would be appreciated.
int main(void)
{
char word[MAX_WORD_LEN + 1];
unsigned wrongGuesses = 0;
int guessedLetters[ALPHABET_SIZE] = {
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
};
init(&word);
printf("%s", word);
displayWord(word, guessedLetters);
guessLetter(word, guessedLetters);
return EXIT_SUCCESS;
}
void init(char* word)
{
int randValue;
char* randWord;
const char* words[NUM_WORDS] = {
"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"
};
int seed;
seed = (time(NULL));
srand(seed);
randValue = rand() % NUM_WORDS;
randWord = words[randValue];
printf("%s", randWord);
*word = randWord;
}