forked from freudenreichan/info2Praktikum-Wortsalat
modified input.c
This commit is contained in:
1 parent
43f85de5a1
commit
b3d425aeb8
2 files changed
+20
No files matched your search
@@ -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)
|
||||
{
|
||||
char line[1024];
|
||||
unsigned int count = 0;
|
||||
|
||||
if (file == NULL)
|
||||
return 0;
|
||||
|
||||
while (count < maxWordCount && fgets(line, sizeof(line), file) != NULL)
|
||||
{
|
||||
char *word = strtok(line, ",; \t\r\n");
|
||||
|
||||
while (word != NULL && count < maxWordCount)
|
||||
{
|
||||
strncpy(words[count], word, MAX_WORD_LEN - 1);
|
||||
words[count][MAX_WORD_LEN - 1] = '\0';
|
||||
|
||||
count++;
|
||||
word = strtok(NULL, ",; \t\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
Executable
BIN
Binary file not shown.
Reference in new issue
Block a user