Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ef4fb6519b |
No files matched your search
@@ -8,33 +8,5 @@
|
|||||||
// Read words from file and store in 'words' array
|
// Read words from file and store in 'words' array
|
||||||
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
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;
|
|
||||||
}
|
|
||||||
@@ -36,10 +36,17 @@ 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:
|
if (wordCount == placedWords)
|
||||||
// Check if all words were successfully placed
|
{
|
||||||
// Start the game if successful
|
|
||||||
// error message if some words couldn't be placed
|
startGame(wordSalad, SALAD_SIZE, words, wordCount, 800);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
fprintf(stderr, "Could only place %u of %u words!\n", placedWords, wordCount);
|
||||||
|
exitCode = EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in new issue
Block a user