diff --git a/Start_Windows/input.c b/Start_Windows/input.c index 321eab5..67084e8 100644 --- a/Start_Windows/input.c +++ b/Start_Windows/input.c @@ -8,22 +8,35 @@ // Read words from file and store in 'words' array int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) { - int wordLength = MAX_WORD_LEN; - - //open file in read mode + char puffer[MAX_LINE_LEN]; + char *teiler = " ,;.\n"; + char *token; file = fopen("words.txt", "r"); if(file == NULL) { - printf("\nNot able to opne file.\n"); - } - else - { - int n = 0; - - while (n < MAX_WORDS && fscanf(file, "%49s", words[n]) == 1) - n++; - + printf("\nNot able to open file.\n"); fclose(file); + return -1; } + + int n = 0; + + while (fgets(puffer, MAX_LINE_LEN, file) != NULL) + { + token = strtok(puffer, teiler); + + while (token != NULL) + { + strncpy(words[n], token, MAX_WORD_LEN); + // printf("Einzelwort: %s\n", words[n]); + + token = strtok(NULL, teiler); + n++; + } + + } + + fclose(file); + return 0; } \ No newline at end of file