generated from freudenreichan/info2Praktikum-Wortsalat
corrected issue at counting words
This commit is contained in:
1 parent
a73810f61c
commit
b685b56273
1 file changed
+3
-5
+3
-5
@@ -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 readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
||||||
{
|
{
|
||||||
int wordCount = 0;
|
int wordCount = 0;
|
||||||
int i = 0;
|
|
||||||
char lineRead[MAX_LINE_LEN];
|
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);
|
wordCount += createSingleWords(lineRead, words + wordCount, maxWordCount - wordCount);
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return i; //wordCount
|
return wordCount; //wordCount
|
||||||
}
|
}
|
||||||
|
|
||||||
static int createSingleWords(char text[MAX_LINE_LEN], char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
static int createSingleWords(char text[MAX_LINE_LEN], char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
||||||
|
|||||||
Reference in new issue
Block a user