From f407d5a36f1044a4d0761c950a3eff6a127f1b75 Mon Sep 17 00:00:00 2001 From: Hofmann Jonas Date: Sat, 25 Oct 2025 21:37:36 +0200 Subject: [PATCH] =?UTF-8?q?funktion=20placeRandomLetters=20f=C3=BCr=20crea?= =?UTF-8?q?teWordSalad=20erg=C3=A4nzt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Start_Windows/game.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Start_Windows/game.c b/Start_Windows/game.c index 08b8025..9923771 100644 --- a/Start_Windows/game.c +++ b/Start_Windows/game.c @@ -115,6 +115,31 @@ int placeWord(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], wordPositi return 1; } +// Places random letters into the +// empty fields of the wordSalad +void placeRandomLetters(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen) +{ + int i = 0; + int j = 0; + + + srand(time(NULL)); + + for (i = 0; i < searchFieldLen; i++) + { + for (j = 0; i < searchFieldLen; j++) + { + if (salad[i][j]) + { + if ((salad[i][j] < 'A') && (salad[i][j] > 'z')) + { + salad[i][j] = rand()%('Z' - 'A' + 1) + 'A'; + } + } + } + } +} + // Creates the word salad by placing words randomly and filling empty spaces // returnes the number of sucessfully placed words @@ -143,6 +168,8 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi placedWords += placeWord(salad, currentWordPosition, currentWord, strlen(currentWord), searchFieldLen); } } + + placeRandomLetters(salad, searchFieldLen); return placedWords;