From 7cdcd0e8dbbe0e254e4c4e9e471d45f3d07abeb8 Mon Sep 17 00:00:00 2001 From: sengpielto106561 Date: Mon, 26 Oct 2026 18:15:25 +0100 Subject: [PATCH] =?UTF-8?q?test=20funktion=20in=20main.c=20implementiert?= =?UTF-8?q?=20(sehr=20=C3=A4hnlich=20der,=20die=20in=20unit=5Ftest.c=20ver?= =?UTF-8?q?wendet=20wird)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Startcode/main.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/Startcode/main.c b/Startcode/main.c index 03da755..9957d65 100644 --- a/Startcode/main.c +++ b/Startcode/main.c @@ -7,6 +7,42 @@ #define MAX_NUMBER_OF_WORDS 100 #define SALAD_SIZE 20 +int checkSalad(char words[][MAX_WORD_LEN], char wordSalad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], int placedWords, int wordCount){ + //Iteriere über alle verfügbaren Wörter + int foundWords = 0; + + //suche horizontal + for(int i = 0; i < wordCount; i++){ + for(int h = 0; h < MAX_SEARCH_FIELD_LEN; h++){ + if(strstr(wordSalad[h], words[i]) != NULL){ + foundWords++; + break; + } + } + } + + //flip Board + char copySalad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN]; + for (int i = 0; i< MAX_SEARCH_FIELD_LEN; i++){ + for (int j = 0; j < MAX_SEARCH_FIELD_LEN; j++){ + copySalad[i][j] = wordSalad[j][i]; + } + } + + // sucher vertikal + for(int i = 0; i < wordCount; i++){ + for(int h = 0; h < MAX_SEARCH_FIELD_LEN; h++){ + if(strstr(copySalad[h], words[i]) != NULL){ + foundWords++; + break; + } + } + } + + if(foundWords == placedWords) return 0; + return -1; +} + int main(int argc, char *argv[]) { int exitCode = EXIT_SUCCESS; @@ -41,6 +77,14 @@ int main(int argc, char *argv[]) // Start the game if successful // error message if some words couldn't be placed + int check = checkSalad(char words[][MAX_WORD_LEN], char wordSalad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], int placedWords, int wordCount); + //Fehlerfall + if(check != 0){ + fprintf(stderr, "Not all words could be placed!\n"); + exitCode = EXIT_FAILURE; + } + //keine Ahnung wiegroß pixelSize sein soll + startGame(wordSalad, MAX_SEARCH_FIELD_LEN, words, placedWords, MAX_SEARCH_FIELD_LEN * 20); } else {