diff --git a/Startcode/game.c b/Startcode/game.c index 7b28299..eab3338 100644 --- a/Startcode/game.c +++ b/Startcode/game.c @@ -13,7 +13,7 @@ int placeWord(const char *word, int wordLength, char salad[MAX_SEARCH_FIELD_LEN] int searchFieldLen, int column, int row, int axis); // Creates the word salad by placing words randomly and filling empty spaces -int createWordSalad( +unsigned int createWordSalad( char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], @@ -41,9 +41,9 @@ int createWordSalad( // Wörter platzieren for (int w = 0; w < wordCount; w++) { - int wordlenght = strlen(words[w]); // Wortlänge festgelegt + int wordlength = strlen(words[w]); // Wortlänge festgelegt - if (wordlenght == 0 || wordlenght > searchFieldLen) + if (wordlength == 0 || wordlength > searchFieldLen) { continue; } @@ -57,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], wordlength, salad, searchFieldLen, column, row, axis); if (success) { @@ -78,7 +78,8 @@ int createWordSalad( } } } - printf("%d placed", placedWords); + + printf("%d placed\n", placedWords); return placedWords; } diff --git a/Startcode/game.h b/Startcode/game.h index cc66572..e7ac9b6 100644 --- a/Startcode/game.h +++ b/Startcode/game.h @@ -5,6 +5,6 @@ #define MAX_SEARCH_FIELD_LEN 100 -int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], unsigned int wordCount); +unsigned int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], unsigned int wordCount); #endif diff --git a/Startcode/input.c b/Startcode/input.c index 2d87c48..ded270d 100644 --- a/Startcode/input.c +++ b/Startcode/input.c @@ -1,22 +1,33 @@ #include "input.h" +#include #include -int readWord(char *buffer, char *divisor, char words[][MAX_WORD_LEN], unsigned int maxWordCount, int *count); +void toUpperCase(char *word); -int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) +unsigned int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) { char buffer[MAX_LINE_LEN]; - int count = 0; + unsigned int count = 0; char *divisor = " ,;.\n"; 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); + strncpy(words[count], word, MAX_WORD_LEN - 1); + words[count][MAX_WORD_LEN - 1] = '\0'; + toUpperCase(words[count]); ++count; } } return count; } + +void toUpperCase(char *word) +{ + for (int i = 0; i < strlen(word); ++i) + { + word[i] = toupper(word[i]); + } +} diff --git a/Startcode/input.h b/Startcode/input.h index 032ec28..265de42 100644 --- a/Startcode/input.h +++ b/Startcode/input.h @@ -6,6 +6,6 @@ #define MAX_WORD_LEN 100 #define MAX_LINE_LEN 1024 -int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount); +unsigned int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount); #endif