done
This commit is contained in:
parent
90bf5a0067
commit
9026fa88ec
@ -8,22 +8,35 @@
|
|||||||
// 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)
|
||||||
{
|
{
|
||||||
int wordLength = MAX_WORD_LEN;
|
char puffer[MAX_LINE_LEN];
|
||||||
|
char *teiler = " ,;.\n";
|
||||||
//open file in read mode
|
char *token;
|
||||||
file = fopen("words.txt", "r");
|
file = fopen("words.txt", "r");
|
||||||
|
|
||||||
if(file == NULL)
|
if(file == NULL)
|
||||||
{
|
{
|
||||||
printf("\nNot able to opne file.\n");
|
printf("\nNot able to open file.\n");
|
||||||
|
fclose(file);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
int n = 0;
|
int n = 0;
|
||||||
|
|
||||||
while (n < MAX_WORDS && fscanf(file, "%49s", words[n]) == 1)
|
while (fgets(puffer, MAX_LINE_LEN, file) != NULL)
|
||||||
|
{
|
||||||
|
token = strtok(puffer, teiler);
|
||||||
|
|
||||||
|
while (token != NULL)
|
||||||
|
{
|
||||||
|
strncpy(words[n], token, MAX_WORD_LEN);
|
||||||
|
// printf("Einzelwort: %s\n", words[n]);
|
||||||
|
|
||||||
|
token = strtok(NULL, teiler);
|
||||||
n++;
|
n++;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
fclose(file);
|
fclose(file);
|
||||||
}
|
return 0;
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user