diff --git a/Start_Windows/game.o b/Start_Windows/game.o index 403f508..c296e50 100644 Binary files a/Start_Windows/game.o and b/Start_Windows/game.o differ diff --git a/Start_Windows/input.c b/Start_Windows/input.c index ed77805..cce1a8a 100644 --- a/Start_Windows/input.c +++ b/Start_Windows/input.c @@ -5,8 +5,43 @@ // 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) { + char zeile[MAX_LINE_LEN]; + char inhalt[MAX_WORD_LEN*maxWordCount]; + char *trenner = " .;,"; + char *token; + char *enter = "\n"; + //Zeilen auslesen und als ein String speichern + while(fgets(zeile,MAX_LINE_LEN, file) != NULL){ + if (strstr(zeile, enter) != NULL){ + zeile[strlen(zeile)-1] = ';'; + } + strncat(inhalt, zeile, strlen(zeile)); + } + + //erstes Wort finden + token = strtok(inhalt, trenner); + + //Woerter auftrennen und in words[][] speichern + int counter = 0; + while(token != NULL){ + strncpy(words[counter], token, MAX_WORD_LEN-1); + words[counter][MAX_WORD_LEN - 1] = '\0'; //Sicherstellen von Stringende + token = strtok(NULL, trenner); + counter ++; + } + + // Datei schliessen + fclose(file); + + //Test + //for(int i =0;i