diff --git a/Startcode/input.c b/Startcode/input.c index ed77805..06c7639 100644 --- a/Startcode/input.c +++ b/Startcode/input.c @@ -8,5 +8,51 @@ // Read words from file and store in 'words' array int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) { + int c; + unsigned int i = 0; // Wort + unsigned int j = 0; // Zeichen im Wort + while ((c = fgetc(file)) != EOF) + { + if (c == ',' || c == ';' || c == '\n' || c == ' ') + { + if (j > 0) + { + words[i][j] = '\0'; + i++; + j = 0; + + if (i >= maxWordCount) + { + break; + } + } + } + else + { + // Auf Pufferüberlauf im Wort achten + if (j < MAX_WORD_LEN - 1) + { + words[i][j] = (char)toupper(c); + j++; + } + } + } + + // Ans Ende \0 hinzufügen + if (j > 0 && i < maxWordCount) + { + words[i][j] = '\0'; + i++; + } + + // MIT CHAT GEMACHT ZUR KONTROLLE: Konsolenausgabe zur Kontrolle der eingelesenen Wörter + printf("Eingelesene Wörter (%u Stück):\n", i); + for (unsigned int idx = 0; idx < i; idx++) + { + printf("%u. Entry: %s\n", idx + 1, words[idx]); + } + + + return i; } \ No newline at end of file