From 420e9b7d8544b54dc168ea7fc862647cf1fcf5de Mon Sep 17 00:00:00 2001 From: Niko Rost Date: Tue, 4 Nov 2025 09:04:35 +0100 Subject: [PATCH] Added check for succesfull word placement in main --- Start_Windows/.idea/.gitignore | 8 ++ Start_Windows/.idea/editor.xml | 248 +++++++++++++++++++++++++++++++++ Start_Windows/.idea/misc.xml | 18 +++ Start_Windows/.idea/vcs.xml | 6 + Start_Windows/main.c | 11 +- 5 files changed, 289 insertions(+), 2 deletions(-) create mode 100644 Start_Windows/.idea/.gitignore create mode 100644 Start_Windows/.idea/editor.xml create mode 100644 Start_Windows/.idea/misc.xml create mode 100644 Start_Windows/.idea/vcs.xml diff --git a/Start_Windows/.idea/.gitignore b/Start_Windows/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/Start_Windows/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/Start_Windows/.idea/editor.xml b/Start_Windows/.idea/editor.xml new file mode 100644 index 0000000..ead1d8a --- /dev/null +++ b/Start_Windows/.idea/editor.xml @@ -0,0 +1,248 @@ + + + + + \ No newline at end of file diff --git a/Start_Windows/.idea/misc.xml b/Start_Windows/.idea/misc.xml new file mode 100644 index 0000000..53624c9 --- /dev/null +++ b/Start_Windows/.idea/misc.xml @@ -0,0 +1,18 @@ + + + + + + + + \ No newline at end of file diff --git a/Start_Windows/.idea/vcs.xml b/Start_Windows/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/Start_Windows/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Start_Windows/main.c b/Start_Windows/main.c index 03da755..e0255b2 100644 --- a/Start_Windows/main.c +++ b/Start_Windows/main.c @@ -22,11 +22,11 @@ int main(int argc, char *argv[]) char words[MAX_NUMBER_OF_WORDS][MAX_WORD_LEN]; // Array to hold the words to be used in the game unsigned int wordCount = 0; - FILE *file = fopen(argv[1], "r"); + FILE *file = fopen(argv[1], "r"); //Opens text document with words if(file != NULL) { - unsigned int placedWords = 0; + unsigned int placedWords = 0; //words actually placed in wordsalad char wordSalad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN]; // 2D array to store the word salad // Read words from file and store in 'words' array @@ -40,6 +40,13 @@ int main(int argc, char *argv[]) // Check if all words were successfully placed // Start the game if successful // error message if some words couldn't be placed + if (placedWords == wordCount && placedWords <= MAX_NUMBER_OF_WORDS) { + exitCode = EXIT_SUCCESS; //Start the game if placed words is equal to words in textfile + } + else { + printf("Error printing words"); + exitCode = EXIT_FAILURE; //Print error message if some words couldn't be placed + } } else