diff --git a/Start_Windows/game.c b/Start_Windows/game.c index 496edaf..db9cdcc 100644 --- a/Start_Windows/game.c +++ b/Start_Windows/game.c @@ -62,5 +62,13 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi // Prints the word salad to console void showWordSalad(const char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen) { + printf("WORTSALAT:\n\n"); + for (int i = 0; i < searchFieldLen; i++) { + for (int j = 0; j < searchFieldLen; j++) { + printf("%c ", salad[i][j]); + } + printf("\n"); + } + } diff --git a/Start_Windows/input.c b/Start_Windows/input.c index 6ea794b..5035661 100644 --- a/Start_Windows/input.c +++ b/Start_Windows/input.c @@ -12,11 +12,24 @@ int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) char text [2000]; char line[200]; int i = 0; + int textcount = 0; + int counter = 0; + char *token; - while (fgets(line, sizeof(line), ptr)) { + while (fgets(line, sizeof(line), file)) { + for (int j = 0; line[j] != '\0'&& i < sizeof(text)-1;j++) { text[i++] = line[j]; + textcount++; + if (textcount>1999) { + break; + } + } + if (textcount>1999) { + + printf("Textdatei zugross!!!"); + return 1; } } @@ -29,25 +42,25 @@ int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) const char *trenner = ",; \n"; token = strtok(text, trenner); - while (token != NULL) { + while (token != NULL&& counter < maxWordCount) { - strncpy(words[zaehler], token, MAX_WORD_LEN - 1); - words[zaehler][MAX_WORD_LEN - 1] = '\0'; + strncpy(words[counter], token, MAX_WORD_LEN - 1); + words[counter][MAX_WORD_LEN - 1] = '\0'; token = strtok(NULL, trenner); - zaehler++; + counter++; } - maxWordCount=zaehler; + //alle Buchstaben in Großbuchstaben ändern - for (int h = 0; h < zaehler; h++) { + for (int h = 0; h < counter; h++) { for (int check = 0; words[h][check] != '\0'; check++) { if (words[h][check] >= 'a' && words[h][check] <= 'z') { words[h][check] -= 32; // direkt ins Array schreiben @@ -56,5 +69,5 @@ int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) } -return 0; +return counter; } \ No newline at end of file