24.10 Änderung 3
This commit is contained in:
parent
2d9fc96112
commit
7e8bbea8a8
@ -8,7 +8,7 @@
|
|||||||
// 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)
|
||||||
{
|
{
|
||||||
//kein fopen und close nötig, weil dies schon in der main passiert und mit *file übergeben wird//
|
//kein fopen und fclose nötig, weil dies schon in der main passiert und mit *file übergeben wird//
|
||||||
|
|
||||||
|
|
||||||
if (file == NULL)
|
if (file == NULL)
|
||||||
@ -20,12 +20,12 @@ if (file == NULL)
|
|||||||
char line[1024];
|
char line[1024];
|
||||||
unsigned int count = 0;
|
unsigned int count = 0;
|
||||||
|
|
||||||
while (fgets(line, sizeof(line), file) && count < maxWordCount)
|
while (fgets(line, sizeof(line), file) && (count < maxWordCount))
|
||||||
{
|
{
|
||||||
line[strcspn(line, "\n")] = '\0';
|
line[strcspn(line, "\n")] = '\0';
|
||||||
|
|
||||||
char *token = strtok(line, " ;,");
|
char *token = strtok(line, " ;,");
|
||||||
while (token && count < maxWordCount)
|
while (token && (count < maxWordCount))
|
||||||
{
|
{
|
||||||
strcpy(words[count], token);
|
strcpy(words[count], token);
|
||||||
count++;
|
count++;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user