input.c errors behoben
This commit is contained in:
1 parent
61c60ebffd
commit
30c53ce8b9
1 file changed
+13
-12
+13
-12
@@ -8,24 +8,25 @@
|
|||||||
// Read words from file and store in 'words' array
|
// Read words from file and store in 'words' array
|
||||||
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
||||||
{
|
{
|
||||||
|
char puffer[MAX_WORD_LEN];
|
||||||
char *teiler = " ,;";
|
char *teiler = " ,;";
|
||||||
char *token;
|
char *token;
|
||||||
unsigned int counter =0;
|
unsigned int wordCount = 0;
|
||||||
|
|
||||||
token = strtok(file, teiler);
|
fgets(puffer, MAX_LINE_LEN, file);
|
||||||
counter += 1;
|
|
||||||
strncpy(words, token, MAX_WORD_LEN);
|
|
||||||
token = strtok(NULL, teiler);
|
|
||||||
counter += 1;
|
|
||||||
|
|
||||||
while(token != NULL)
|
token = strtok(puffer, teiler);
|
||||||
|
|
||||||
|
while(token != NULL && wordCount < maxWordCount)
|
||||||
{
|
{
|
||||||
stncat(words, token, MAX_WORD_LEN);
|
strncpy(words[wordCount], token, MAX_WORD_LEN -1);
|
||||||
token = strtok(NULL, teiler);
|
words[wordCount][MAX_WORD_LEN - 1] = '\0';
|
||||||
counter += 1;
|
|
||||||
|
wordCount++;
|
||||||
|
|
||||||
|
token =strtok(NULL, teiler);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return counter;
|
return wordCount;
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user