From 90827c9ad680747d29be75b58e7fa2d6755e4cf9 Mon Sep 17 00:00:00 2001 From: Jan Uhlmann Date: Sun, 2 Nov 2025 13:21:15 +0100 Subject: [PATCH 1/4] input.c besteht alle Tests --- Start_Windows/input.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/Start_Windows/input.c b/Start_Windows/input.c index ed77805..2018efc 100644 --- a/Start_Windows/input.c +++ b/Start_Windows/input.c @@ -1,4 +1,5 @@ #include "input.h" +#include #include #include @@ -6,7 +7,39 @@ // 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 buffer[MAX_WORD_LEN]; + unsigned int count = 0; -} \ No newline at end of file + if (file == NULL) { + return 1; + } + + while (fgets(buffer, sizeof(buffer), file) != NULL) + { + // Zerlege Zeile in einzelne Wörter anhand der Trennzeichen + char *token = strtok(buffer, " ,;\n"); + while (token != NULL && count < maxWordCount) + { + // In Großbuchstaben umwandeln + for (int i = 0; token[i] != '\0'; i++) { + token[i] = toupper((unsigned char)token[i]); + } + + // Token in das words-Array kopieren + strncpy(words[count], token, MAX_WORD_LEN - 1); + words[count][MAX_WORD_LEN - 1] = '\0'; // sicher terminieren + + count++; + + // Nächsten Token holen + token = strtok(NULL, " ,;\n"); + } + } + + fclose(file); + + return count; +} From ed4a9c7520e5e1b13c44b0881920e56d4d10cfaf Mon Sep 17 00:00:00 2001 From: Simon Wiesend Date: Sun, 2 Nov 2025 20:24:02 +0100 Subject: [PATCH 2/4] sync linux folder --- Start_Linux/input.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/Start_Linux/input.c b/Start_Linux/input.c index ed77805..2018efc 100644 --- a/Start_Linux/input.c +++ b/Start_Linux/input.c @@ -1,4 +1,5 @@ #include "input.h" +#include #include #include @@ -6,7 +7,39 @@ // 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 buffer[MAX_WORD_LEN]; + unsigned int count = 0; -} \ No newline at end of file + if (file == NULL) { + return 1; + } + + while (fgets(buffer, sizeof(buffer), file) != NULL) + { + // Zerlege Zeile in einzelne Wörter anhand der Trennzeichen + char *token = strtok(buffer, " ,;\n"); + while (token != NULL && count < maxWordCount) + { + // In Großbuchstaben umwandeln + for (int i = 0; token[i] != '\0'; i++) { + token[i] = toupper((unsigned char)token[i]); + } + + // Token in das words-Array kopieren + strncpy(words[count], token, MAX_WORD_LEN - 1); + words[count][MAX_WORD_LEN - 1] = '\0'; // sicher terminieren + + count++; + + // Nächsten Token holen + token = strtok(NULL, " ,;\n"); + } + } + + fclose(file); + + return count; +} From 0aa5c5e9e3fb69f89a468ea1f28bea14244a451f Mon Sep 17 00:00:00 2001 From: Simon Wiesend Date: Sun, 2 Nov 2025 20:25:54 +0100 Subject: [PATCH 3/4] update gitignore --- .gitignore | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index b7aac8b..6fe2dc2 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,8 @@ main.o graphicalGame.o wordsalad wordsalad_initial.exe -runTests.exe \ No newline at end of file +runTests.exe +testwords_delims.txt +testwords_empty.txt +testwords_simple.txt +.vscode \ No newline at end of file From 69f9945fe0110ef182ced2732b3bb053e3941352 Mon Sep 17 00:00:00 2001 From: Simon Wiesend Date: Sun, 2 Nov 2025 20:28:35 +0100 Subject: [PATCH 4/4] remove fclose() because it's already called in main.c --- Start_Linux/input.c | 8 ++++---- Start_Windows/input.c | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Start_Linux/input.c b/Start_Linux/input.c index 2018efc..ceab0b6 100644 --- a/Start_Linux/input.c +++ b/Start_Linux/input.c @@ -13,7 +13,8 @@ int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) char buffer[MAX_WORD_LEN]; unsigned int count = 0; - if (file == NULL) { + if (file == NULL) + { return 1; } @@ -24,7 +25,8 @@ int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) while (token != NULL && count < maxWordCount) { // In Großbuchstaben umwandeln - for (int i = 0; token[i] != '\0'; i++) { + for (int i = 0; token[i] != '\0'; i++) + { token[i] = toupper((unsigned char)token[i]); } @@ -39,7 +41,5 @@ int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) } } - fclose(file); - return count; } diff --git a/Start_Windows/input.c b/Start_Windows/input.c index 2018efc..ceab0b6 100644 --- a/Start_Windows/input.c +++ b/Start_Windows/input.c @@ -13,7 +13,8 @@ int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) char buffer[MAX_WORD_LEN]; unsigned int count = 0; - if (file == NULL) { + if (file == NULL) + { return 1; } @@ -24,7 +25,8 @@ int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) while (token != NULL && count < maxWordCount) { // In Großbuchstaben umwandeln - for (int i = 0; token[i] != '\0'; i++) { + for (int i = 0; token[i] != '\0'; i++) + { token[i] = toupper((unsigned char)token[i]); } @@ -39,7 +41,5 @@ int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) } } - fclose(file); - return count; }