From a02b363e20e070fc33e90766fa0170cd2addf7d9 Mon Sep 17 00:00:00 2001 From: sengpielto106561 Date: Sun, 25 Oct 2026 15:44:45 +0100 Subject: [PATCH] implemented return value --- Startcode/game.c | 4 +++- Startcode/input-t.c | 29 +++++++++++++++++++++++++++++ Startcode/input.c | 2 +- 3 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 Startcode/input-t.c diff --git a/Startcode/game.c b/Startcode/game.c index 3ddaadc..1cc2f74 100644 --- a/Startcode/game.c +++ b/Startcode/game.c @@ -69,6 +69,7 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi for (int i = 0; i < (int)len; i++){ salad[x][y+i] = currentWord[i]; } + placedWords++; break; } @@ -83,7 +84,7 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi break; } } - + //if not all spaces are empty try again if(cont) continue; @@ -91,6 +92,7 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi for (int i = 0; i < (int)len; i++){ salad[x+1][y] = currentWord[i]; } + placedWords++; } } return placedWords; diff --git a/Startcode/input-t.c b/Startcode/input-t.c new file mode 100644 index 0000000..668b730 --- /dev/null +++ b/Startcode/input-t.c @@ -0,0 +1,29 @@ +//Torbens Kopie +#include "input.h" +#include +#include + +// TODO: +// eine Funktion implementieren, die ein einzelnes Wort aus einer Textdatei (words.txt) einliest und als C-String zurückgibt. + +// Read words from file and store in 'words' array +int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) +{ + char *tmp; + int counter = 0; + const char delimiters[] = ",!.;:? " + while(fgets(tmp, MAX_WORD_LEN, flie) != NULL){ + char *token = strtok_r (tmp, delimiters, &delimiters); + if(strncpy(words[counter], token, MAX_WORD_LEN) == NULL){ + //failure + return -1; + } + counter++; + while(token != NULL){ + token = strtpk_r (NULL, delimiters, &delimiters); + strncpy(words[counter], token, MAX_WORD_LEN); + counter++; + } + } + return counter; +} \ No newline at end of file diff --git a/Startcode/input.c b/Startcode/input.c index ed77805..b4ea2ec 100644 --- a/Startcode/input.c +++ b/Startcode/input.c @@ -8,5 +8,5 @@ // Read words from file and store in 'words' array int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) { - + } \ No newline at end of file