From a1a0b615a70cc91e6bb0aa554bc6d53f87b66d72 Mon Sep 17 00:00:00 2001 From: Mihaela Creciun Date: Tue, 20 Oct 2026 22:18:24 +0200 Subject: [PATCH] Implementierung der Worteinlesefunktion --- Startcode/input.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/Startcode/input.c b/Startcode/input.c index ed77805..271e2ec 100644 --- a/Startcode/input.c +++ b/Startcode/input.c @@ -8,5 +8,46 @@ // Read words from file and store in 'words' array int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) { + if (file == NULL || words == NULL || maxWordCount == 0) { + return 0; + } + unsigned int count = 0; + size_t length = 0; + int tooLong = 0; + int ch; + + while (count < maxWordCount && (ch = fgetc(file)) != EOF) { + + if (ch == ',' || ch == ';' || isspace((unsigned char)ch)) { + + if (length > 0 && !tooLong) { + words[count][length] = '\0'; + count++; + } + + length = 0; + tooLong = 0; + } + else if (!tooLong) { + + if (length < MAX_WORD_LEN - 1) { + words[count][length] = + (char)toupper((unsigned char)ch); + length++; + } + else { + tooLong = 1; + length = 0; + } + } + } + + if (count < maxWordCount && length > 0 && !tooLong) { + words[count][length] = '\0'; + count++; + } + + return (int)count; + } \ No newline at end of file