diff --git a/Startcode/input.c b/Startcode/input.c index ed77805..ec40672 100644 --- a/Startcode/input.c +++ b/Startcode/input.c @@ -8,5 +8,25 @@ // Read words from file and store in 'words' array int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) { + if (file == NULL) { + return 0; + } +char line[MAX_LINE_LEN]; +unsigned int count = 0; +while (fgets(line, sizeof(line), file) != NULL && count < maxWordCount) { + char *token = strtok(line, " ,;\n\r\t"); + while (token != NULL & count < maxWordCount) { + if (strlen(token) > 0) { + strncpy(words[count], token, MAX_WORD_LEN - 1); + words[count][MAX_WORD_LEN - 1] = '\0'; + for (int i= 0; words[count][i] != '\0'; i++) { + words[count][i] = toupper((unsigned char)words[count][i]); + } + count++; + } + token = strtok(NULL, " ,;\n\r\t"); + } +} +return count; } \ No newline at end of file