diff --git a/Startcode/input.c b/Startcode/input.c index 271e2ec..9c197ab 100644 --- a/Startcode/input.c +++ b/Startcode/input.c @@ -13,16 +13,18 @@ int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) } unsigned int count = 0; + char currentWord[MAX_WORD_LEN]; size_t length = 0; int tooLong = 0; int ch; - + while (count < maxWordCount && (ch = fgetc(file)) != EOF) { if (ch == ',' || ch == ';' || isspace((unsigned char)ch)) { if (length > 0 && !tooLong) { - words[count][length] = '\0'; + currentWord[length] = '\0'; + strncpy(words[count], currentWord, MAX_WORD_LEN); count++; } @@ -32,8 +34,7 @@ int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) else if (!tooLong) { if (length < MAX_WORD_LEN - 1) { - words[count][length] = - (char)toupper((unsigned char)ch); + currentWord[length] = (char)toupper((unsigned char)ch); length++; } else { @@ -44,10 +45,11 @@ int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) } if (count < maxWordCount && length > 0 && !tooLong) { - words[count][length] = '\0'; + currentWord[length] = '\0'; + strncpy(words[count], currentWord, MAX_WORD_LEN); count++; } return (int)count; - + } \ No newline at end of file