diff --git a/Start_Windows/game.c b/Start_Windows/game.c index c2b9505..9e0ca7a 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] = ' '; + salad[i][j] = EMPTY_CHAR; } } @@ -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/input.c b/Start_Windows/input.c index c8aca43..59c730d 100644 --- a/Start_Windows/input.c +++ b/Start_Windows/input.c @@ -1,42 +1,38 @@ -#include "input.h" +#include #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[MAX_WORD_LEN]; + char buffer[1024]; // größerer Puffer für ganze Zeile unsigned int count_word = 0; - while (count_word < maxWordCount && fgets(buffer, sizeof(buffer), file) != NULL) { + // Zeilenumbruch entfernen + buffer[strcspn(buffer, "\r\n")] = '\0'; - // Zeilenumbruch manuell entfernen - for (int i = 0; i < MAX_WORD_LEN; i++) + // Zerlege Zeile in Wörter anhand von Leerzeichen, Komma und Semikolon + char *token = strtok(buffer, " ,;"); + + while (token != NULL && count_word < maxWordCount) { - if (buffer[i] == '\n' || buffer[i] == '\r') - { - buffer[i] = '\0'; - break; - } + 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, " ,;"); } - - 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/makefile b/Start_Windows/makefile index b7e3603..0d023a2 100644 --- a/Start_Windows/makefile +++ b/Start_Windows/makefile @@ -33,6 +33,8 @@ game.o: game.c graphicalGame.o: graphicalGame.c $(CC) -I$(raylib_folder) -c $(CFLAGS) graphicalGame.c + + # -------------------------- # Unit Tests # -------------------------- @@ -41,8 +43,16 @@ TEST_BIN = runTests test: input.o game.o unit_tests.c $(CC) $(CFLAGS) -I$(unityfolder) -o $(TEST_BIN) input.o game.o unit_tests.c $(BINARIES)/libunity.a +$(BINARIES)/libwordsalad_complete.a: input.o game.o + ar rcs $(BINARIES)/libwordsalad_complete.a input.o game.o + + +wordsalad_myversion: main.o $(BINARIES)/libwordsalad_complete.a $(BINARIES)/libraylib.a + $(CC) $(CFLAGS) -o wordsalad_myversion main.o $(BINARIES)/libwordsalad_complete.a $(BINARIES)/libraylib.a $(LDFLAGS) + # -------------------------- # Clean # -------------------------- clean: del /f *.o *.exe + diff --git a/Start_Windows/windows/libwordsalad.a b/Start_Windows/windows/libwordsalad.a deleted file mode 100644 index 55ba658..0000000 Binary files a/Start_Windows/windows/libwordsalad.a and /dev/null differ diff --git a/Start_Windows/windows/libwordsalad_complete.a b/Start_Windows/windows/libwordsalad_complete.a index 817f48e..12567cb 100644 Binary files a/Start_Windows/windows/libwordsalad_complete.a and b/Start_Windows/windows/libwordsalad_complete.a differ diff --git a/Start_Windows/wordsalad_initial.exe b/Start_Windows/wordsalad_initial.exe index 1992bba..65ae92c 100644 Binary files a/Start_Windows/wordsalad_initial.exe and b/Start_Windows/wordsalad_initial.exe differ