Создание простой игры в палач в C. У меня есть опыт работы на Java, и у меня возникают проблемы с методом guessLetter. Я пытаюсь определить, является ли символ, введенный пользователем символом в слове. Хотя, если вы видите какие-либо другие проблемы или имеете какие-либо советы для меня, все это оценили!Передача переменных в C - Создание игры палача
// Includes
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "hangman.h"
//Function Declarations
void getRandomWord(char* word);
// Global Variable Declarations
int wordLength = 0;
//Main Function
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
};
srand(time(NULL));
getRandomWord(word);
displayWord(word, wordLength);
guessLetter(word, guessedLetters);
return EXIT_SUCCESS;
}
//Gets Random Word from Words Array
void getRandomWord(char* word)
{
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 randomNumber = rand() % NUM_WORDS;
printf("Random Number is: %d\n", randomNumber);
wordLength = strlen(words[randomNumber]);
printf("Word Length is: %d\nWord is: %s\n", wordLength, words[randomNumber]);
word = words[randomNumber];
return word;
}
//Prints Word Formatted with dashes
void displayWord(char* word, int* guessedLetters)
{
int x = 0;
printf("%s \n", word);
for (x = 0; x <= wordLength * 2; x++)
{
printf("=");
}
printf("\n|");
for(x = 0; x < wordLength; x++)
{
if (word[x] != guessedLetters)
{
printf("_|");
}
else
{
printf(guessedLetters);
}
}
printf("\n");
for (x = 0; x <= wordLength * 2; x++)
{
printf("=");
}
}
//User Makes Guess, Determines whether Guess is Correct or Incorrect
int guessLetter(char* word, int* guessedLetters)
{
char firstGuess;
int x;
//puts(word); will print an @ and another strange symbol! This is where my problem is!
printf("\nEnter Your Guess: ");
scanf("%d\n", firstGuess);
for(x = 0; x < wordLength; x++)
{
if(firstGuess == word[x])
{
printf("Correct Guess!!");
return GOOD_GUESS;
}
else
{
printf("Incorrect");
return BAD_GUESS;
}
}
// Once a correct Guess is made that character will be added to the guessedLetters Array
}
Независимо от того, ess, Неправильный Угадай всегда печатается, поскольку я чувствую, что слово неправильно передается, когда я пытаюсь его распечатать, я получаю знак @. Noobie Quesiton Я знаю! – Luke
И вопрос в том, что? Вы должны изменить вопрос с этой информацией, а затем предоставить важную часть комментариев. – John
Попробуйте отбросить. Самое сложное слово, чтобы угадать в hangman –