corrected issue at counting words

This commit is contained in:
Andreas Binner committed 2026-10-26 13:43:09 +01:00
1 parent a73810f61c
commit b685b56273
1 file changed
+3 -5
+3 -5
View File
@@ -12,16 +12,14 @@ static int createSingleWords(char text[MAX_LINE_LEN], char words[][MAX_WORD_LEN]
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
{
int wordCount = 0;
int i = 0;
char lineRead[MAX_LINE_LEN];
while(fgets(lineRead, MAX_LINE_LEN, file) != NULL && i < maxWordCount)
while(fgets(lineRead, MAX_LINE_LEN, file) != NULL && wordCount < (int)maxWordCount)
{
wordCount += createSingleWords(lineRead, words, maxWordCount);
i++;
wordCount += createSingleWords(lineRead, words + wordCount, maxWordCount - wordCount);
}
return i; //wordCount
return wordCount; //wordCount
}
static int createSingleWords(char text[MAX_LINE_LEN], char words[][MAX_WORD_LEN], unsigned int maxWordCount)