From 4299c3979ef73053372e54f44d266b41c888e0d9 Mon Sep 17 00:00:00 2001 From: gsqsimjaa Date: Thu, 30 Oct 2025 16:11:59 +0100 Subject: [PATCH] input fertig --- Start_Mac/input.c | 17 +++++++++++++++++ Start_Windows/input.c | 17 +++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/Start_Mac/input.c b/Start_Mac/input.c index ed77805..dcec983 100644 --- a/Start_Mac/input.c +++ b/Start_Mac/input.c @@ -1,12 +1,29 @@ #include "input.h" #include #include +#define MAX_WORD_LEN 100 // 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 anzahlWoerter = 0; +char zeile[500]; + int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) { + while(anzahlWoerter <= maxWordCount && fgets(zeile, sizeof(zeile), file)){ + char *wort[] = strtok(zeile, ",; \n"); + while(wort != NULL && anzahlWoerter <= maxWordCount){ + strncpy(words[anzahlWoerter], wort, anzahlWoerter -1); + words[anzahlWoerter][MAX_WORD_LEN - 1]= '\0'; + anzahlWoerter++; + wort = strtok(NULL, ",; \n"); + + } + + + } + return anzahlWoerter; } \ No newline at end of file diff --git a/Start_Windows/input.c b/Start_Windows/input.c index ed77805..dcec983 100644 --- a/Start_Windows/input.c +++ b/Start_Windows/input.c @@ -1,12 +1,29 @@ #include "input.h" #include #include +#define MAX_WORD_LEN 100 // 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 anzahlWoerter = 0; +char zeile[500]; + int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) { + while(anzahlWoerter <= maxWordCount && fgets(zeile, sizeof(zeile), file)){ + char *wort[] = strtok(zeile, ",; \n"); + while(wort != NULL && anzahlWoerter <= maxWordCount){ + strncpy(words[anzahlWoerter], wort, anzahlWoerter -1); + words[anzahlWoerter][MAX_WORD_LEN - 1]= '\0'; + anzahlWoerter++; + wort = strtok(NULL, ",; \n"); + + } + + + } + return anzahlWoerter; } \ No newline at end of file