diff --git a/Start_Windows/input.c b/Start_Windows/input.c index ed77805..a72759b 100644 --- a/Start_Windows/input.c +++ b/Start_Windows/input.c @@ -9,4 +9,32 @@ int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) { + char puffer[256]; + char *teiler = " ,;.\n"; + char *token; + unsigned int wordCount = 0; + + /* wird words.txt schon in main geöffnet? + file = fopen ("words.txt", "r"); // Öffne words.txt zum lesen + + if (file == NULL) + { + return -1; + } + */ + + while (fgets (puffer, 256, file) != NULL) //liest words.txt ein und speichert es in puffer + { + token = strtok(puffer, teiler); //token teilt erstes Wort und speichert es in sich ab + + while (token != NULL && wordCount < maxWordCount) + { + strncpy(words[wordCount], token, MAX_WORD_LEN -1); //kopiert das Wort von token in das array words + words[wordCount][MAX_WORD_LEN-1] = '\0'; + wordCount++; + token = strtok (NULL, teiler); //nächstes Wort + } + } + + return wordCount; //Anzahl der gelesenen Wörter } \ No newline at end of file