2 changed files with 33 additions and 12 deletions

No files matched your search

+29 -1
View File
@@ -8,5 +8,33 @@
// 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;
}
+4 -11
View File
@@ -36,17 +36,10 @@ int main(int argc, char *argv[])
// Create the word salad by placing words into grid
placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount);
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;
}
// TODO:
// Check if all words were successfully placed
// Start the game if successful
// error message if some words couldn't be placed
}
else