generated from freudenreichan/info2Praktikum-Wortsalat
Bugfix
This commit is contained in:
parent
111d1ce238
commit
328931806c
@ -8,22 +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 trennzeichen = " ,;";
|
|
||||||
char zeile [MAX_LINE_LEN]; //1024
|
char puffer[MAX_LINE_LEN]; //Array für eingelesene Zeile
|
||||||
int anzahlWörter;
|
int counter = 0; //Zähler für Anzahl eingelesener Wörter
|
||||||
while (fgets(zeile, MAX_WORD_LEN - 1, file) != 0){
|
int i;
|
||||||
char *token = strtok(zeile, trennzeichen);
|
|
||||||
while (token != NULL)
|
while(fgets(puffer, MAX_LINE_LEN-1, file) != NULL && counter < maxWordCount)
|
||||||
|
{
|
||||||
|
char *word_parts = strtok(puffer, ",;\n\t/. "); //Wörter aufteilen
|
||||||
|
|
||||||
|
while(word_parts != NULL && counter < maxWordCount)
|
||||||
{
|
{
|
||||||
// Wort ins Array kopieren, Länge begrenzen
|
for(i = 0; i < MAX_WORD_LEN -1 && word_parts[i] != '\0'; i++)
|
||||||
strncpy(words[anzahlWörter], token, MAX_WORD_LEN - 1);
|
{
|
||||||
words[anzahlWörter][MAX_WORD_LEN - 1] = '\0';
|
words[counter][i] = toupper(word_parts[i]); //Großbuchstaben erzeugen
|
||||||
|
}
|
||||||
anzahlWörter++;
|
words[counter][i] = '\0'; //Stringdefinition vervollständigen
|
||||||
|
|
||||||
if (anzahlWörter >= maxWordCount) break;
|
|
||||||
|
|
||||||
*token = strtok(NULL, trennzeichen);
|
|
||||||
}
|
}
|
||||||
}
|
counter++; // Wort eingelesen, Wortzähler erhöhen
|
||||||
|
word_parts = strtok(NULL, ",;\n\t/. "); //NULL für Zeiger angeben
|
||||||
|
}
|
||||||
|
return counter;
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user