From 1ca4567185f747411295f88a9eba9f8e002faff1 Mon Sep 17 00:00:00 2001 From: kachelto100370 Date: Tue, 4 Nov 2025 03:39:16 +0100 Subject: [PATCH] =?UTF-8?q?f=C3=BCrs=20erste=20fertige=20input.c=20datei?= =?UTF-8?q?=20(hoffentlich)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Start_Linux/input.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Start_Linux/input.c b/Start_Linux/input.c index b68814d..a6149bb 100644 --- a/Start_Linux/input.c +++ b/Start_Linux/input.c @@ -6,24 +6,23 @@ // 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 puffer[MAX_WORD_LEN]; + file = fopen("words.txt", "r"); if (file == NULL) { - perror("File couldn't be opened"); + return -1; } - char fehlerhafterString[MAX_LINE_LEN]; - char *teiler = " ;,.\n"; + char teiler[] = " ;,.\n"; char *aktuellesWort; int wortAnzahl = 0; - while (fgets(fehlerhafterString, sizeof(fehlerhafterString), file) != NULL && wortAnzahl < maxWordCount) + while (fgets(puffer, MAX_WORD_LEN, file) != NULL) { - aktuellesWort = strtok(fehlerhafterString, teiler); + aktuellesWort = strtok(puffer, teiler); while (aktuellesWort != NULL && wortAnzahl < maxWordCount) {