From a0523f0ad3a88eb2c7d520781645204b1d21265b Mon Sep 17 00:00:00 2001 From: jw Date: Thu, 30 Oct 2025 15:22:48 +0100 Subject: [PATCH] input funktioniert eigentlich --- Start_Windows/input.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/Start_Windows/input.c b/Start_Windows/input.c index ed77805..b01a51f 100644 --- a/Start_Windows/input.c +++ b/Start_Windows/input.c @@ -1,3 +1,4 @@ +#include #include "input.h" #include #include @@ -5,8 +6,35 @@ // 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) { + unsigned int count = 0; + // größerer Zeilenpuffer, falls mehrere Wörter/Delimiter in einer Zeile stehen + char line[4 * MAX_WORD_LEN]; + const char *DELIMS = " ,;:.-_!?\t\r\n()[]{}\"'/\\"; + + while (count < maxWordCount && fgets(line, sizeof(line), file)) { + // Zeilenende entfernen + line[strcspn(line, "\r\n")] = '\0'; -} \ No newline at end of file + // Tokenisieren nach Delimitern (auch wenn keine Spaces dazwischen sind) + for (char *tok = strtok(line, DELIMS); + tok && count < maxWordCount; + tok = strtok(NULL, DELIMS)) + { + // Uppercase (ASCII-sicher) + for (char *p = tok; *p; ++p) + *p = (char)toupper((unsigned char)*p); + + // Sicher kopieren + nullterminieren + strncpy(words[count], tok, MAX_WORD_LEN - 1); + words[count][MAX_WORD_LEN - 1] = '\0'; + count++; + } + } + return (int)count; +} + + + \ No newline at end of file