Author SHA1 Message Date
Simon ef4fb6519b main: Spielstart und Fehlermeldung ergaenzt 2026-10-29 10:35:38 +01:00
2 changed files with 12 additions and 33 deletions

No files matched your search

+1 -29
View File
@@ -8,33 +8,5 @@
// Read words from file and store in 'words' array
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
{
unsigned int wordCount=0;// die beiden Zähler also hier fertige wörter werden hier gespeichert
unsigned int letterCount=0;// zählt die gespeicherten zeichen der aktuellen wörter
int character;
//ungültige parameter müssen abgefragt werden
if (file == NULL || words == NULL || maxWordCount == 0) {
return 0;
}
// datei zeichen für zeichen lesen & fgetc (file get character) E0F (end of file)
while (wordCount < maxWordCount && (character = fgetc(file)) != EOF)
{
//leerräume tc trennen die wörter
if (isspace(character) || character == ',' || character == ';') {
if (letterCount > 0) {
words[wordCount] [letterCount] = '\0';
wordCount++;
letterCount=0;
}
} else if (letterCount < MAX_WORD_LEN -1 ) {
words[wordCount] [letterCount] = (char)toupper (character);// to uppercase
letterCount++;
}
}
// letzes wort speicher, auch ohne trennzeichen am datei ende
if (letterCount > 0 && wordCount < maxWordCount) {
words[wordCount] [letterCount] = '\0';
wordCount++;
}
return (int)wordCount;
}
}
+11 -4
View File
@@ -36,10 +36,17 @@ int main(int argc, char *argv[])
// Create the word salad by placing words into grid
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 (wordCount == placedWords)
{
startGame(wordSalad, SALAD_SIZE, words, wordCount, 800);
}
else
{
fprintf(stderr, "Could only place %u of %u words!\n", placedWords, wordCount);
exitCode = EXIT_FAILURE;
}
}
else