diff --git a/Startcode/input.c b/Startcode/input.c index ed77805..3403000 100644 --- a/Startcode/input.c +++ b/Startcode/input.c @@ -8,5 +8,27 @@ // Read words from file and store in 'words' array int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) { + char puffer[MAX_LINE_LEN]; + char *teiler = " ,;\n"; + char *token; + FILE *words_txt_speicherort; //Zeiger auf den Speicherort der word.txt Datei + words_txt_speicherort = fopen("words.txt","r"); //word.txt öffnen + + if(words_txt_speicherort == NULL) //Abbruch falls words.txt nicht existieren würde + { + return -1; + } + + fgets(puffer, MAX_LINE_LEN, words_txt_speicherort); //speichert alle Zeichen der words.txt datei in den speicher + + token = strtok(puffer, teiler); //Trennt das erste Wort der Zeichenkette, abhängig von den Teilerbedingungen + + while(token != NULL) + + words = token; //speichert nur das einzelne Word in das words array; Problem: Laufindex der global gespeichert werden müsste; wie springe ich beim 2ten Funktionsaufruf zum nächsten Wort + + + + int fclose(words_txt_speicherort); } \ No newline at end of file diff --git a/Startcode/input.h b/Startcode/input.h index 032ec28..6c58ddf 100644 --- a/Startcode/input.h +++ b/Startcode/input.h @@ -6,6 +6,6 @@ #define MAX_WORD_LEN 100 #define MAX_LINE_LEN 1024 -int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount); +int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount); #endif