#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) { //fopen und fclose bereits, in der main und mit *file übergeben // if (file == NULL) { perror("Error invalid pointer to file"); return -1; } char line[1024]; unsigned int count = 0; while (fgets(line, sizeof(line), file) && (count < maxWordCount)) { line[strcspn(line, "\n")] = '\0'; char *token = strtok(line, " ;,"); while (token && (count < maxWordCount)) { for (int i = 0; token[i] != '\0'; i++) { token[i] = toupper(token[i]); } strcpy(words[count], token); count++; token = strtok(NULL, " ;,"); } } return count; }