Game Output implementiert

This commit is contained in:
2025-10-20 14:55:17 +02:00
parent bc913662a2
commit 48c0aadace
3 changed files with 59 additions and 1 deletions
+25
View File
@@ -8,5 +8,30 @@
// Read words from file and store in 'words' array
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
{
char lines [1024]; //TODO: Sinnvolle Begrenzung finden
int word_counter = 0;
while (fgets(lines, sizeof(lines) , file) != NULL)
{
for (int i = 0; lines[i] != '\0'; i++) //Entfernen von \n aus dem String
{
if (lines[i] == '\n')
{
lines[i] = '\0';
break;
}
}
char *single_word = strtok(lines, " ;,");
while (single_word != NULL && word_counter < maxWordCount)
{
strncpy(words[word_counter], single_word, MAX_WORD_LEN - 1);
words [word_counter][MAX_WORD_LEN -1] = '\0'; //Zur Sicherheit, damit \0 auf alle Fälle vorhanden ist
word_counter++;
single_word = strtok(NULL, " ;,");
}
}
return word_counter;
}