generated from freudenreichan/info2Praktikum-Wortsalat
input bearbeitet
This commit is contained in:
parent
1db2042e38
commit
1fb5db8a4f
@ -8,5 +8,22 @@
|
|||||||
// 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 trennzeichen = " ,;";
|
||||||
|
char zeile [MAX_LINE_LEN]; //1024
|
||||||
|
int anzahlWörter;
|
||||||
|
while (fgets(zeile, MAX_WORD_LEN - 1, file) != 0){
|
||||||
|
char *token = strtok(zeile, trennzeichen);
|
||||||
|
while (token != NULL)
|
||||||
|
{
|
||||||
|
// Wort ins Array kopieren, Länge begrenzen
|
||||||
|
strncpy(words[anzahlWörter], token, MAX_WORD_LEN - 1);
|
||||||
|
words[anzahlWörter][MAX_WORD_LEN - 1] = '\0';
|
||||||
|
|
||||||
|
anzahlWörter++;
|
||||||
|
|
||||||
|
if (anzahlWörter >= maxWordCount) break;
|
||||||
|
|
||||||
|
*token = strtok(NULL, trennzeichen);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user