diff --git a/Startcode/input.c b/Startcode/input.c index 2504d9f..395d7af 100644 --- a/Startcode/input.c +++ b/Startcode/input.c @@ -8,24 +8,25 @@ // Read words from file and store in 'words' array int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) { - + char puffer[MAX_WORD_LEN]; char *teiler = " ,;"; char *token; - unsigned int counter =0; + unsigned int wordCount = 0; - token = strtok(file, teiler); - counter += 1; - strncpy(words, token, MAX_WORD_LEN); - token = strtok(NULL, teiler); - counter += 1; + fgets(puffer, MAX_LINE_LEN, file); - while(token != NULL) + token = strtok(puffer, teiler); + + while(token != NULL && wordCount < maxWordCount) { - stncat(words, token, MAX_WORD_LEN); - token = strtok(NULL, teiler); - counter += 1; + strncpy(words[wordCount], token, MAX_WORD_LEN -1); + words[wordCount][MAX_WORD_LEN - 1] = '\0'; + + wordCount++; + + token =strtok(NULL, teiler); } - - return counter; + + return wordCount; } \ No newline at end of file