diff --git a/Start_Windows/input.c b/Start_Windows/input.c index 1b94f99..9caad62 100644 --- a/Start_Windows/input.c +++ b/Start_Windows/input.c @@ -8,21 +8,20 @@ // Read words from file and store in 'words' array int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) { - //Erstellt Pointer auf textdokument - FILE *textdokument = fopen(file, "r"); - if (textdokument == NULL) { + if (file == NULL) { printf("Datei konnte nicht geoffnet werden"); + return 0; } // 2D char Array um wörter zu speichern char word[MAX_WORD_LEN]; unsigned int count = 0; - while (fscanf(textdokument, "%s", word) != EOF && count < maxWordCount) { + while (fscanf(file, "%s", word) != EOF && count < maxWordCount) { // Kopiere das gelesene Wort in das 2D-Array strncpy(words[count], word, MAX_WORD_LEN - 1); words[count][MAX_WORD_LEN - 1] = '\0'; // Sicherstellen, dass der String nullterminiert ist count++; } - fclose(textdokument); + fclose(file); return count;