Browse Source

refactoring: Definition der konstanten Variablen LISTSIZE MAX_WORD_LENGTH und ersetzen an den jeweiligen Stellen

remotes/origin/tim
fdai7727 11 months ago
parent
commit
0a7e4513bd
  1. 11
      src/main/c/Tim/hangman.c

11
src/main/c/Tim/hangman.c

@ -4,7 +4,10 @@
#include <stdlib.h> #include <stdlib.h>
#include <time.h> #include <time.h>
char wordlist[10][30] = {
#define LISTSIZE 10
#define MAX_WORD_LENGTH 30
char wordlist[LISTSIZE][MAX_WORD_LENGTH] = {
"Kartoffel", "Zigarette", "Haus", "Fenster", "Kartenleseettiketiergeraet", "Kartoffel", "Zigarette", "Haus", "Fenster", "Kartenleseettiketiergeraet",
"Kleiderschrank", "Schnee","Wasserhahn", "Kleiderschrank", "Schnee","Wasserhahn",
"Fernbedienung", "Computertastatur" "Fernbedienung", "Computertastatur"
@ -22,10 +25,10 @@ void hangman()
do do
{ {
char guessWord[30];
char displayWord[30];
char guessWord[MAX_WORD_LENGTH];
char displayWord[MAX_WORD_LENGTH];
int length; int length;
strcpy(guessWord,wordlist[rand() % 10]);
strcpy(guessWord,wordlist[rand() % LISTSIZE]);
length = strlen(guessWord); length = strlen(guessWord);
printf("%s %d\n",guessWord, length); printf("%s %d\n",guessWord, length);
for (int i = 0; i <= length; i++) for (int i = 0; i <= length; i++)

Loading…
Cancel
Save