diff --git a/Startcode/input.c b/Startcode/input.c index 3403000..2504d9f 100644 --- a/Startcode/input.c +++ b/Startcode/input.c @@ -8,27 +8,24 @@ // 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 *teiler = " ,;"; char *token; - FILE *words_txt_speicherort; //Zeiger auf den Speicherort der word.txt Datei + unsigned int counter =0; - 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 + token = strtok(file, teiler); + counter += 1; + strncpy(words, token, MAX_WORD_LEN); + token = strtok(NULL, teiler); + counter += 1; while(token != NULL) + { + stncat(words, token, MAX_WORD_LEN); + token = strtok(NULL, teiler); + counter += 1; - 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); + return counter; } \ No newline at end of file