diff --git a/Start_Windows/game.c b/Start_Windows/game.c index 9e0ca7a..c2b9505 100644 --- a/Start_Windows/game.c +++ b/Start_Windows/game.c @@ -22,7 +22,7 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi { for (unsigned int j = 0; j < searchFieldLen; ++j) { - salad[i][j] = EMPTY_CHAR; + salad[i][j] = ' '; } } @@ -90,7 +90,7 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi { if (salad[i][j] == EMPTY_CHAR) { - salad[i][j] = 'A' + (rand() % 26); + salad[i][j] = 'A' + rand() % 26; } } } diff --git a/Start_Windows/game.o b/Start_Windows/game.o new file mode 100644 index 0000000..4a9ecf9 Binary files /dev/null and b/Start_Windows/game.o differ diff --git a/Start_Windows/input.c b/Start_Windows/input.c index 59c730d..c8aca43 100644 --- a/Start_Windows/input.c +++ b/Start_Windows/input.c @@ -1,38 +1,42 @@ -#include +#include "input.h" #include #include -#define MAX_WORD_LEN 100 -void capitalletters(char *str) { +void capitalletters(char *str){ while (*str) { - *str = toupper((unsigned char)*str); - str++; - } -} + *str = toupper((unsigned char) *str); + str++; + } +} +// Liest Wörter aus Datei und speichert sie sicher im Array int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) { - char buffer[1024]; // größerer Puffer für ganze Zeile + char buffer[MAX_WORD_LEN]; unsigned int count_word = 0; + while (count_word < maxWordCount && fgets(buffer, sizeof(buffer), file) != NULL) { - // Zeilenumbruch entfernen - buffer[strcspn(buffer, "\r\n")] = '\0'; - // Zerlege Zeile in Wörter anhand von Leerzeichen, Komma und Semikolon - char *token = strtok(buffer, " ,;"); - - while (token != NULL && count_word < maxWordCount) + // Zeilenumbruch manuell entfernen + for (int i = 0; i < MAX_WORD_LEN; i++) { - capitalletters(token); // Großschreiben - strncpy(words[count_word], token, MAX_WORD_LEN - 1); - words[count_word][MAX_WORD_LEN - 1] = '\0'; // Nullterminierung - count_word++; - - token = strtok(NULL, " ,;"); + if (buffer[i] == '\n' || buffer[i] == '\r') + { + buffer[i] = '\0'; + break; + } } + + capitalletters(buffer); + + // Sicheres Kopieren in das Zielarray + strncpy(words[count_word], buffer, MAX_WORD_LEN - 1); + words[count_word][MAX_WORD_LEN - 1] = '\0'; // Nullterminierung sicherstellen + + count_word++; } return count_word; diff --git a/Start_Windows/input.o b/Start_Windows/input.o new file mode 100644 index 0000000..5a70047 Binary files /dev/null and b/Start_Windows/input.o differ diff --git a/Start_Windows/main.c b/Start_Windows/main.c index 5b1aa74..e1fef58 100644 --- a/Start_Windows/main.c +++ b/Start_Windows/main.c @@ -36,16 +36,10 @@ int main(int argc, char *argv[]) // 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) { - // Start the game + // Start the game if successful unsigned int windowSize = 900; //FRAGE: Programm so programmieren, dass man das weglassen kann startGame(wordSalad, SALAD_SIZE, words, wordCount, windowSize); } @@ -56,7 +50,6 @@ int main(int argc, char *argv[]) exitCode = EXIT_FAILURE; } - } else { diff --git a/Start_Windows/runTests.exe b/Start_Windows/runTests.exe new file mode 100644 index 0000000..8fed2fe Binary files /dev/null and b/Start_Windows/runTests.exe differ