fertig 2.0

This commit is contained in:
hentschdu103698 committed 2026-11-03 16:27:16 +01:00
1 parent 6259f06391
commit 4e556279e5
9 files changed
+141 -94

No files matched your search

+21 -14
View File
@@ -6,45 +6,52 @@
#define MAX_NUMBER_OF_WORDS 100
#define SALAD_SIZE 20
#define WINDOW_SIZE 700
int main(int argc, char *argv[])
{
int exitCode = EXIT_SUCCESS;
// Check if the correct number of arguments is provided
if(argc != 2)
if (argc != 2)
{
fprintf(stderr, "Usage: %s <path to file with search words>\n", argv[0]);
fprintf(stderr, "%s Textdatei mit angeben\n", argv[0]);
exitCode = EXIT_FAILURE;
}
else
{
char words[MAX_NUMBER_OF_WORDS][MAX_WORD_LEN]; // Array to hold the words to be used in the game
char words[MAX_NUMBER_OF_WORDS][MAX_WORD_LEN];
unsigned int wordCount = 0;
FILE *file = fopen(argv[1], "r");
if(file != NULL)
if (file != NULL)
{
unsigned int placedWords = 0;
char wordSalad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN]; // 2D array to store the word salad
char wordSalad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN];
// Read words from file and store in 'words' array
wordCount = readWords(file, words, MAX_NUMBER_OF_WORDS);
fclose(file);
// 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 (placedWords == wordCount)
{
startGame(wordSalad, SALAD_SIZE, words, wordCount, WINDOW_SIZE);
}
else
{
fprintf(stderr, "Only %u of %u words could be placed in the word salad.\n", placedWords, wordCount);
exitCode = EXIT_FAILURE;
}
}
else
{
// Print error message if file couldn't be opened
fprintf(stderr, "Could not open file %s for reading ...\n", argv[1]);
exitCode = EXIT_FAILURE;
}