From 405ffbd8050af59817ce518ab8c29a27089bb1b5 Mon Sep 17 00:00:00 2001 From: luis Date: Tue, 4 Nov 2025 09:12:06 +0100 Subject: [PATCH] =?UTF-8?q?input=20.=20c=20unvollst=C3=A4ndig?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Start_Windows/input.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/Start_Windows/input.c b/Start_Windows/input.c index e0e3042..29b1aa4 100644 --- a/Start_Windows/input.c +++ b/Start_Windows/input.c @@ -6,26 +6,36 @@ // 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 -// f gets ; komma und semikolon erkennen und alles in groß buchstaben (=uppercase) +// f gets ; komma und semikolon erkennen und alles in groß buchstaben (=uppercase) (strtok) int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) { + char delimiter[] = ", ; \n"; + char string[MAX_WORD_LEN]; + char stringcopy[MAX_WORD_LEN]; + char *stringptr; + file = fopen("words.txt", "r"); if (file == NULL) { printf("Fehler: Datei konnte nicht geöffnet werden!\n"); return 1; } - else (file != NULL) - { + else + { printf("Datei konnte geöffnet werden"); + fgets(string, MAX_WORD_LEN, file); + strcpy(stringcopy, string); + stringptr = strtok(stringcopy, delimiter); + while (stringptr != NULL){ + stringptr = strtok(NULL, delimiter); + maxWordCount ++; + + } } } -} -/* - char words[MAX_LINE_LEN][MAX_WORD_LEN]; - unsigned int wordCount =0;*/ \ No newline at end of file +