From c2d35dfe890ad716f17b2f9ae7e1d6bf2a539032 Mon Sep 17 00:00:00 2001 From: Jonas Hruschka Date: Wed, 28 Oct 2026 22:20:01 +0100 Subject: [PATCH] Entfernen von doppelter else func --- Startcode/input.c | 5 +++-- Startcode/main.c | 23 ++++++----------------- 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/Startcode/input.c b/Startcode/input.c index a87fa3e..36cc59b 100644 --- a/Startcode/input.c +++ b/Startcode/input.c @@ -23,7 +23,8 @@ int readWords(FILE *file, char words[][MAX_WORD_LEN], char *word = strtok(line, " ,;\n\t\r"); - while (word != NULL && wordCount < maxWordCount) { + while (word != NULL && wordCount < maxWordCount) + { strncpy(words[wordCount], word, MAX_WORD_LEN - 1); words[wordCount][MAX_WORD_LEN - 1] = '\0'; @@ -31,7 +32,7 @@ int readWords(FILE *file, char words[][MAX_WORD_LEN], while (words[wordCount][i] != '\0') { words[wordCount][i] = - (char)toupper((unsigned char)words[wordCount][i]); + (char)toupper((unsigned char)words[wordCount][i]);// char davor da toupper einen int wert liefert und einen unsigned char bekommt i++; } diff --git a/Startcode/main.c b/Startcode/main.c index 0932dae..462641e 100644 --- a/Startcode/main.c +++ b/Startcode/main.c @@ -9,8 +9,7 @@ #define MAX_NUMBER_OF_WORDS 100 #define SALAD_SIZE 20 -int main(int argc, char *argv[]) -{ +int main(int argc, char *argv[]) { int exitCode = EXIT_SUCCESS; srand(time(NULL)); //Seed für Zufallszahlen @@ -21,8 +20,7 @@ int main(int argc, char *argv[]) fprintf(stderr, "Usage: %s \n", argv[0]); exitCode = EXIT_FAILURE; } - else - { + else { char words[MAX_NUMBER_OF_WORDS][MAX_WORD_LEN]; // Array to hold the words to be used in the game unsigned int wordCount = 0; @@ -47,21 +45,12 @@ int main(int argc, char *argv[]) } else { - // Fehler beim Erstellen des Wortsalats - fprintf(stderr, - "Fehler beim Erstellen des Wortsalats. Rueckgabewert: %d\n", - (int)placedWords); + // Print error message if file couldn't be opened + fprintf(stderr, "Could not open file %s for reading ...\n", argv[1]); 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; - } + return exitCode; } - - return exitCode; } \ No newline at end of file