diff --git a/Start_Windows/.idea/editor.xml b/Start_Windows/.idea/editor.xml index 95d51a7..1f0ef49 100644 --- a/Start_Windows/.idea/editor.xml +++ b/Start_Windows/.idea/editor.xml @@ -1,484 +1,6 @@ - \ No newline at end of file diff --git a/Start_Windows/input.c b/Start_Windows/input.c index 2ca069d..91edce8 100644 --- a/Start_Windows/input.c +++ b/Start_Windows/input.c @@ -7,28 +7,28 @@ // 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) -{ - char zeile[MAX_LINE_LEN]; - char* teiler = ".;, "; - int wordCount = 0; - char* token; - printf("Datei geöffnet\n"); - while(fgets(zeile, MAX_LINE_LEN, file)!=NULL) +int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) { + char zeile[MAX_LINE_LEN]; + char* teiler = ".;, "; + int wordCount = 0; + char* token; + while(fgets(zeile, MAX_LINE_LEN, file)!=NULL) + { + for (int i = 0; i < 1024; i++) { - for (int i = 0; i < 1024; i++) - if (zeile[i] == '\n') { - zeile[i] = '\0'; - break; - } - } - token = strtok(zeile,teiler); - while(token != NULL) + if (zeile[i] == '\n') { - strcpy(words[wordCount],token); - token = strtok(NULL,teiler); - wordCount++; + zeile[i] = '\0'; + break; } } - return wordCount; + token = strtok(zeile,teiler); + while(token != NULL && wordCount <= maxWordCount) + { + strcpy(words[wordCount],token); + token = strtok(NULL,teiler); + wordCount++; + } + } + return wordCount; } \ No newline at end of file