From 5cea6d7c4da07b57683bc1f86d468d03b062d950 Mon Sep 17 00:00:00 2001 From: silvana884 Date: Tue, 4 Nov 2025 20:33:14 +0100 Subject: [PATCH] Rueckgabewert von createWordSalad fuer Debugging geandert --- Start_Windows/game.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/Start_Windows/game.c b/Start_Windows/game.c index 5c35d52..23b3774 100644 --- a/Start_Windows/game.c +++ b/Start_Windows/game.c @@ -15,16 +15,27 @@ // Creates the word salad by placing words randomly and filling empty spaces int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], unsigned int wordCount) { + int placedChar = 0; srand(time(NULL)); - int usedWords[MAX_NUMBERS_OF_WORDS]; - for(int i=0; i< MAX_NUMBERS_OF_WORDS; i++){ + int usedWords[MAX_NUMBER_OF_WORDS]; + for(int i=0; i< MAX_NUMBER_OF_WORDS; i++){ usedWords[i] = -1; } fillSalad(salad, searchFieldLen, words, wordCount, usedWords); showWordSalad(salad, searchFieldLen); - return 1; + for(int i= 0; i < MAX_SEARCH_FIELD_LEN; i++) + { + for(int j=0; j < MAX_SEARCH_FIELD_LEN; j++) + { + if(salad[i][j] != '\0') + { + placedChar++; + } + } + } + return placedChar; } // Prints the word salad to console @@ -52,7 +63,7 @@ int printHorizontal(unsigned int wordCount) // returns 1, when empty spaces are left int emptyPlaces(unsigned int wordCount) { - if(wordCount < MAX_NUMBERS_OF_WORDS) + if(wordCount < MAX_NUMBER_OF_WORDS) { return 1; } @@ -61,7 +72,7 @@ int emptyPlaces(unsigned int wordCount) // fills salad array with max. words from word array either horizontally or vertically -void fillSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], unsigned int wordCount, int usedWords[MAX_NUMBERS_OF_WORDS]) +void fillSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], unsigned int wordCount, int usedWords[MAX_NUMBER_OF_WORDS]) { // empties salad for(int i = 0; i < searchFieldLen; i++) { @@ -133,7 +144,7 @@ void fillSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned } -int whichWord(const char words[][MAX_WORD_LEN], unsigned int wordCount, int usedWords[MAX_NUMBERS_OF_WORDS]) +int whichWord(const char words[][MAX_WORD_LEN], unsigned int wordCount, int usedWords[MAX_NUMBER_OF_WORDS]) { int tries = 0; @@ -141,7 +152,7 @@ int whichWord(const char words[][MAX_WORD_LEN], unsigned int wordCount, int used int numWord = rand() % wordCount; // 0..wordCount-1 int alreadyUsed = 0; - for(int f = 0; f < MAX_NUMBERS_OF_WORDS; f++){ + for(int f = 0; f < MAX_NUMBER_OF_WORDS; f++){ if(usedWords[f] == numWord){ alreadyUsed = 1; break; // word already used @@ -150,7 +161,7 @@ int whichWord(const char words[][MAX_WORD_LEN], unsigned int wordCount, int used if(!alreadyUsed){ // Eintragen in usedWords - for(int f = 0; f < MAX_NUMBERS_OF_WORDS; f++){ + for(int f = 0; f < MAX_NUMBER_OF_WORDS; f++){ if(usedWords[f] == -1){ // unused usedWords[f] = numWord; break;