From 9f0c31513460c1825bf4dccecf31131b003007fd Mon Sep 17 00:00:00 2001 From: Lukas Dunkel Date: Wed, 28 Oct 2026 09:36:11 +0100 Subject: [PATCH] Mein fertiger Input. --- Startcode/input.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/Startcode/input.c b/Startcode/input.c index 5c15491..2a84557 100644 --- a/Startcode/input.c +++ b/Startcode/input.c @@ -8,5 +8,39 @@ // Read words from file and store in 'words' array int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) { + int c = 0; + int count = 0; + int letterCount = 0; + while (count < maxWordCount) + { + while ((c = fgetc(file)) != EOF) //Leerzeichen prüfen + { + if (isspace(c) || !isalpha(c)) { + if (letterCount > 0) { + break; //Wort fertig eingelesen + } -}dhckhdkfhdjf \ No newline at end of file + continue; // mehrere Leerzeichen oder Sonderzeichen überspringen + } + + if (letterCount < MAX_WORD_LEN - 1) //wörter Buchstabenweise einlesen + { + words[count][letterCount] = (char)toupper(c); + letterCount++; + } + } + + if (letterCount == 0) { + break; //kein weiteres Wort gefunden + } + + words[count][letterCount] = '\0'; + letterCount = 0; + count++; + + if (c == EOF) { + break; + } + } + return count; +} \ No newline at end of file