From e94da31756fbf1a772b4edfbdcd2ffcd84dc1d4f Mon Sep 17 00:00:00 2001 From: Tobias Linz Date: Thu, 29 Oct 2026 16:00:21 +0100 Subject: [PATCH] Format Project --- .clang-format | 23 ++++------------------- Startcode/game.c | 23 ++++++++++++++++------- Startcode/input.c | 11 +++++------ Startcode/main.c | 15 ++++++++------- 4 files changed, 33 insertions(+), 39 deletions(-) diff --git a/.clang-format b/.clang-format index 1ee516b..0df8ecc 100644 --- a/.clang-format +++ b/.clang-format @@ -1,45 +1,30 @@ -# clang-format-Konfiguration, abgeleitet aus dem bestehenden Wortsalat-Code BasedOnStyle: LLVM -# Einrückung: 4 Leerzeichen, keine Tabs IndentWidth: 4 TabWidth: 4 UseTab: Never ContinuationIndentWidth: 4 -# Allman-Stil: geschweifte Klammern für Funktionen, Schleifen, if/else stehen in eigenen Zeilen BreakBeforeBraces: Allman -# Keine automatischen Zeilenumbrüche, der Code bricht lange Zeilen bereits selbst um ColumnLimit: 0 ReflowComments: false -# Zeiger-Sternchen rechts: char *word, SearchWord *words PointerAlignment: Right DerivePointerAlignment: false -# Kein Leerzeichen vor der Klammer bei if/for/while und bei Funktionsaufrufen -SpaceBeforeParens: Custom -SpaceBeforeParensOptions: - AfterControlStatements: false - AfterFunctionDeclarationName: false - AfterFunctionDefinitionName: false -SpaceAfterCStyleCast: false - -# Kurze Konstrukte bleiben mehrzeilig AllowShortIfStatementsOnASingleLine: Never AllowShortLoopsOnASingleLine: false AllowShortBlocksOnASingleLine: Never AllowShortFunctionsOnASingleLine: None AllowShortCaseLabelsOnASingleLine: false -# Geschweifte Initialisierer: {0, 0} +InsertBraces: true + Cpp11BracedListStyle: true -# Includes nicht umsortieren (Reihenfolge ist teils bewusst gewählt) -SortIncludes: Never -IncludeBlocks: Preserve +SortIncludes: CaseSensitive +IncludeBlocks: Regroup -# Leerzeilen MaxEmptyLinesToKeep: 2 KeepEmptyLinesAtTheStartOfBlocks: true diff --git a/Startcode/game.c b/Startcode/game.c index 5c49ee8..7b28299 100644 --- a/Startcode/game.c +++ b/Startcode/game.c @@ -1,14 +1,15 @@ #include "game.h" -#include + +#include #include #include -#include +#include #define MAX_RAND_TRIES_PER_WORD 10 #define EMPTY_CHAR 0 -int placeWord(const char* word, int wordLength, char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], +int placeWord(const char *word, int wordLength, char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], int searchFieldLen, int column, int row, int axis); // Creates the word salad by placing words randomly and filling empty spaces @@ -19,7 +20,9 @@ int createWordSalad( unsigned int wordCount) { if (searchFieldLen == 0 || searchFieldLen > MAX_SEARCH_FIELD_LEN) + { return 0; + } int placedWords = 0; @@ -27,8 +30,12 @@ int createWordSalad( // Spielfeld leeren: for (int x = 0; x < searchFieldLen; x++) + { for (int y = 0; y < searchFieldLen; y++) + { salad[x][y] = EMPTY_CHAR; + } + } // Wörter platzieren @@ -37,7 +44,9 @@ int createWordSalad( int wordlenght = strlen(words[w]); // Wortlänge festgelegt if (wordlenght == 0 || wordlenght > searchFieldLen) + { continue; + } for (int attempts = 0; attempts < MAX_RAND_TRIES_PER_WORD; @@ -48,7 +57,7 @@ int createWordSalad( int row = rand() % searchFieldLen; int column = rand() % searchFieldLen; - int success = placeWord( words[w],wordlenght, salad, searchFieldLen, column, row, axis); + int success = placeWord(words[w], wordlenght, salad, searchFieldLen, column, row, axis); if (success) { @@ -69,12 +78,12 @@ int createWordSalad( } } } - printf("%d placed" ,placedWords); + printf("%d placed", placedWords); return placedWords; } -int placeWord(const char* word, int wordLength, char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], +int placeWord(const char *word, int wordLength, char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], int searchFieldLen, int column, int row, int axis) { // Available space check & word collision avoidance @@ -112,4 +121,4 @@ int placeWord(const char* word, int wordLength, char salad[MAX_SEARCH_FIELD_LEN] } return 1; -} \ No newline at end of file +} diff --git a/Startcode/input.c b/Startcode/input.c index 0344b2b..2d87c48 100644 --- a/Startcode/input.c +++ b/Startcode/input.c @@ -1,14 +1,17 @@ #include "input.h" + #include int readWord(char *buffer, char *divisor, char words[][MAX_WORD_LEN], unsigned int maxWordCount, int *count); -int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) { +int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) +{ char buffer[MAX_LINE_LEN]; int count = 0; char *divisor = " ,;.\n"; - while (fgets(buffer, MAX_LINE_LEN, file) != NULL) { + while (fgets(buffer, MAX_LINE_LEN, file) != NULL) + { for (char *word = strtok(buffer, divisor); word != NULL && count < maxWordCount; word = strtok(NULL, divisor)) { strncpy(words[count], word, MAX_WORD_LEN); @@ -17,7 +20,3 @@ int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) } return count; } - - - - diff --git a/Startcode/main.c b/Startcode/main.c index 9b48a9a..f66e93a 100644 --- a/Startcode/main.c +++ b/Startcode/main.c @@ -1,8 +1,9 @@ -#include -#include -#include "input.h" #include "game.h" #include "graphicalGame.h" +#include "input.h" + +#include +#include #define MAX_NUMBER_OF_WORDS 100 #define SALAD_SIZE 20 @@ -11,7 +12,7 @@ int main(int argc, char *argv[]) { // Check if the correct number of arguments is provided - if(argc != 2) + if (argc != 2) { fprintf(stderr, "Usage: %s \n", argv[0]); return EXIT_FAILURE; @@ -21,7 +22,7 @@ int main(int argc, char *argv[]) unsigned int wordCount = 0; FILE *file = fopen(argv[1], "r"); - if(file == NULL) + if (file == NULL) { // Print error message if file couldn't be opened fprintf(stderr, "Could not open file %s for reading ...\n", argv[1]); @@ -35,7 +36,7 @@ int main(int argc, char *argv[]) wordCount = readWords(file, words, MAX_NUMBER_OF_WORDS); fclose(file); - if(wordCount == 0) + if (wordCount == 0) { fprintf(stderr, "No words found...\n"); return EXIT_FAILURE; @@ -44,7 +45,7 @@ int main(int argc, char *argv[]) // Create the word salad by placing words into grid placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount); - if(placedWords != wordCount) + if (placedWords != wordCount) { fprintf(stderr, "Could not place %u out of %u words ...\n", wordCount - placedWords, wordCount); return EXIT_FAILURE;