From 0a7e4513bd4174005101a98d992cc4fb4cd54e97 Mon Sep 17 00:00:00 2001 From: fdai7727 Date: Thu, 25 Jan 2024 19:43:28 +0100 Subject: [PATCH] refactoring: Definition der konstanten Variablen LISTSIZE MAX_WORD_LENGTH und ersetzen an den jeweiligen Stellen --- src/main/c/Tim/hangman.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/c/Tim/hangman.c b/src/main/c/Tim/hangman.c index df569e2..0e63451 100644 --- a/src/main/c/Tim/hangman.c +++ b/src/main/c/Tim/hangman.c @@ -4,7 +4,10 @@ #include #include -char wordlist[10][30] = { +#define LISTSIZE 10 +#define MAX_WORD_LENGTH 30 + +char wordlist[LISTSIZE][MAX_WORD_LENGTH] = { "Kartoffel", "Zigarette", "Haus", "Fenster", "Kartenleseettiketiergeraet", "Kleiderschrank", "Schnee","Wasserhahn", "Fernbedienung", "Computertastatur" @@ -22,10 +25,10 @@ void hangman() do { - char guessWord[30]; - char displayWord[30]; + char guessWord[MAX_WORD_LENGTH]; + char displayWord[MAX_WORD_LENGTH]; int length; - strcpy(guessWord,wordlist[rand() % 10]); + strcpy(guessWord,wordlist[rand() % LISTSIZE]); length = strlen(guessWord); printf("%s %d\n",guessWord, length); for (int i = 0; i <= length; i++)