diff --git a/I2_Wortsalat/Start_Mac/input.c b/I2_Wortsalat/Start_Mac/input.c index ed77805..9c4ef16 100644 --- a/I2_Wortsalat/Start_Mac/input.c +++ b/I2_Wortsalat/Start_Mac/input.c @@ -8,5 +8,30 @@ // Read words from file and store in 'words' array int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) { + char lines [1024]; //TODO: Sinnvolle Begrenzung finden + int word_counter = 0; + while (fgets(lines, sizeof(lines) , file) != NULL) + { + for (int i = 0; lines[i] != '\0'; i++) //Entfernen von \n aus dem String + { + if (lines[i] == '\n') + { + lines[i] = '\0'; + break; + } + } + + char *single_word = strtok(lines, " ;,"); + + while (single_word != NULL && word_counter < maxWordCount) + { + strncpy(words[word_counter], single_word, MAX_WORD_LEN - 1); + words [word_counter][MAX_WORD_LEN -1] = '\0'; //Zur Sicherheit, damit \0 auf alle Fälle vorhanden ist + word_counter++; + single_word = strtok(NULL, " ;,"); + } + } + + return word_counter; } \ No newline at end of file diff --git a/I2_Wortsalat/Start_Windows/game.c b/I2_Wortsalat/Start_Windows/game.c index d8cc133..b9d31a9 100644 --- a/I2_Wortsalat/Start_Windows/game.c +++ b/I2_Wortsalat/Start_Windows/game.c @@ -14,10 +14,18 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], unsigned int wordCount) { + + } // Prints the word salad to console void showWordSalad(const char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen) { - + for( int i = 0; i < searchFieldLen; i++ ) + { + for( int j = 0; j < searchFieldLen; j++ ) + { + printf("%c", salad[i][j]); + } + } } diff --git a/I2_Wortsalat/Start_Windows/input.c b/I2_Wortsalat/Start_Windows/input.c index ed77805..9c4ef16 100644 --- a/I2_Wortsalat/Start_Windows/input.c +++ b/I2_Wortsalat/Start_Windows/input.c @@ -8,5 +8,30 @@ // Read words from file and store in 'words' array int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) { + char lines [1024]; //TODO: Sinnvolle Begrenzung finden + int word_counter = 0; + while (fgets(lines, sizeof(lines) , file) != NULL) + { + for (int i = 0; lines[i] != '\0'; i++) //Entfernen von \n aus dem String + { + if (lines[i] == '\n') + { + lines[i] = '\0'; + break; + } + } + + char *single_word = strtok(lines, " ;,"); + + while (single_word != NULL && word_counter < maxWordCount) + { + strncpy(words[word_counter], single_word, MAX_WORD_LEN - 1); + words [word_counter][MAX_WORD_LEN -1] = '\0'; //Zur Sicherheit, damit \0 auf alle Fälle vorhanden ist + word_counter++; + single_word = strtok(NULL, " ;,"); + } + } + + return word_counter; } \ No newline at end of file