Kleine Veränderung am main

This commit is contained in:
midzicer103376 committed 2026-10-15 20:54:01 +03:00
1 parent f728fee70a
commit 0095775e73
2 files changed
+24 -8

No files matched your search

+13 -4
View File
@@ -37,7 +37,6 @@ int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
if(fptr != NULL) if(fptr != NULL)
{ {
/*Bis man bis zum letzten Platz in der Zeile eintragen kann*/
while(*fptr != '\0' && count < maxWordCount) while(*fptr != '\0' && count < maxWordCount)
{ {
while(*fptr == '\n' || *fptr == ',' || *fptr == ';' || *fptr == ' ' || *fptr == '\t' || *fptr == '\r') while(*fptr == '\n' || *fptr == ',' || *fptr == ';' || *fptr == ' ' || *fptr == '\t' || *fptr == '\r')
@@ -59,13 +58,23 @@ int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
} }
fptr++; fptr++;
/*geht auf die naechste Addresse.*/ /*geht auf die naechste Addresse.*/
/*falls man raus aus dieser Schleife geht, heisst das, dass man
ein Wort eingelesen hat, da die oben in der Schleife benannten Characters
genau diejenige sind, die die Woerter trennen.*/
} }
/*Wir schliessen das Wort ab mit einem Null-Terminator.*/ while (char_Index < MAX_WORD_LEN)
{
words[count][char_Index] = '\0'; words[count][char_Index] = '\0';
count++; /*naechste Zeile*/ char_Index++;
}
/*Wir fuellen den Rest der Zeile mit \0, falls es noch
uebrigen Platz gibt (weniger Buchstaben eingelesen als es Raum in der Zeile gibt.)*/
count++;
}
} }
}
return count; return count;
} }
+11 -4
View File
@@ -38,12 +38,19 @@ int main(int argc, char *argv[])
// Create the word salad by placing words into grid // Create the word salad by placing words into grid
placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount); placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount);
// TODO:
// Check if all words were successfully placed
// Start the game if successful
// error message if some words couldn't be placed
if (placedWords == wordCount) // Prueft, ob alle Woerter platziert wurden.
{
printf("Alle %u Woerter wurden platziert!\n", placedWords); // Gibt eine Erfolgsmeldung aus.
startGame(wordSalad, SALAD_SIZE, words, wordCount, WINDOW_WIDTH); // Startet das grafische Wortsalat-Spiel.
} }
else // Wird ausgefuehrt, wenn nicht alle Woerter platziert wurden.
{
fprintf(stderr, "Nur %u von %u Woertern platziert!\n", placedWords, wordCount); // Gibt eine Fehlermeldung aus.
exitCode = EXIT_FAILURE; // Kennzeichnet das Programm als fehlgeschlagen.
}
}
else else
{ {
// Print error message if file couldn't be opened // Print error message if file couldn't be opened