From 9a7d3d3766f1b4f00ffde7a4508884e1c0d39bc6 Mon Sep 17 00:00:00 2001 From: Tobias Busch Date: Sun, 2 Nov 2025 21:28:15 +0100 Subject: [PATCH] input --- Start_Mac/input.c | 48 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/Start_Mac/input.c b/Start_Mac/input.c index 5ce243e..86fea6f 100644 --- a/Start_Mac/input.c +++ b/Start_Mac/input.c @@ -8,7 +8,49 @@ // Read words from file and store in 'words' array int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) { - FILE *fopen (const char *file, const char *r); // != NULL??? + unsigned int count = 0; - fclose(*file ); -} \ No newline at end of file + char line[MAX_LINE_LEN]; + char *teiler = " ,;"; + char *token; + + while(fgets(line, sizeof(line), file)){ + + //Yeti,Nessie Werwolf; Vampir + // token = Yeti + token = strtok(line, teiler); + + while (token != NULL) + { + if (strlen(token) >= MAX_WORD_LEN) { + printf("Fehler: eigelesenes Wort ist zu lang\n"); + return count; + } + if (count >= maxWordCount){ + printf("Fehler: zu viele Wörter\n"); + return count; + } + + strncpy(words[count], token, MAX_WORD_LEN-1); + words[count][MAX_WORD_LEN-1] = '\0'; + + //Nessie Werwolf; Vampir + //token= Nessie + token = strtok(NULL, teiler); + + count++; + } + } + + return count; +} + + +// 00M 01a 02x +// 10W 11a 12l 13t 14e 15r +// 20T 21o 22b 23i 24a 25s + +// array[3][2] +// 00 01 +// 10 11 +// 20 21