input und anzeige überarbeitet

This commit is contained in:
Björn 2025-10-27 13:24:06 +01:00
parent 817ddc0e35
commit 9d8a760f08
3 changed files with 15 additions and 7 deletions

View File

@ -14,23 +14,25 @@ int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
// Alle gewünschten Trennzeichen // Alle gewünschten Trennzeichen
const char *delimiters = " \t\n,.;:!?\"'()[]{}"; const char *delimiters = " \t\n,.;:!?\"'()[]{}";
while (fgets(line, sizeof(line), file) && count < maxWordCount) { // Zeile für Zeile lesen
while (fgets(line, sizeof(line), file) != NULL && count < maxWordCount) {
// Tokenize Zeile nach Trennzeichen
char *token = strtok(line, delimiters); char *token = strtok(line, delimiters);
while (token != NULL && count < maxWordCount) { while (token != NULL && count < maxWordCount) {
// Alles in Großbuchstaben umwandeln // Alles in Großbuchstaben umwandeln
for (int i = 0; token[i]; i++) { for (int i = 0; token[i]; i++) {
token[i] = toupper(token[i]); token[i] = toupper(token[i]);
} }
// Wort ins Array kopieren
strncpy(words[count], token, MAX_WORD_LEN - 1); strncpy(words[count], token, MAX_WORD_LEN - 1);
words[count][MAX_WORD_LEN - 1] = '\0'; // Nullterminierung words[count][MAX_WORD_LEN - 1] = '\0';
count++; count++;
token = strtok(NULL, delimiters); token = strtok(NULL, delimiters);
} }
} }
fclose(file); return count; // Datei nicht schließen gehört dem Aufrufer
return count;
} }

View File

@ -62,7 +62,9 @@ int main(int argc, char *argv[])
if(placedWords == wordCount) if(placedWords == wordCount)
{ {
// Start the game with the created word salad // Start the game with the created word salad
startGame(wordSalad, SALAD_SIZE, words, wordCount, placedWords); printf("Squares: %u, Words: %u\n", SALAD_SIZE, placedWords);
unsigned int windowWidth = 800;
startGame(wordSalad, SALAD_SIZE, words, wordCount, windowWidth);
} }
else else
{ {

View File

@ -1 +1,5 @@
test Yeti,Nessie Werwolf; Vampir
Monster
Hydra;Frankenstein
Dracula;KingKong;Gremlin;Kobold,Hexe;Poltergeist
Gespenst, Oger