#include "input.h" #include #include // 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 readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) { if (file == NULL) return 0; unsigned int count = 0; char line[512]; // Lese Datei zeilenweise while (fgets(line, sizeof(line), file) != NULL && count < maxWordCount) { // Zerlege die Zeile in Tokens (Wörter), getrennt durch gängige Delimiter char *token = strtok(line, " ,;:.!?\"\n\r\t"); while (token != NULL && count < maxWordCount) { // In Großbuchstaben umwandeln for (int i = 0; token[i]; i++) token[i] = toupper((unsigned char)token[i]); // Wort kopieren strncpy(words[count], token, MAX_WORD_LEN - 1); words[count][MAX_WORD_LEN - 1] = '\0'; count++; token = strtok(NULL, " ,;:.!?\"\n\r\t"); } } return count; }