diff --git a/Start_Mac/game.c b/Start_Mac/game.c index a1fb95e..92db454 100644 --- a/Start_Mac/game.c +++ b/Start_Mac/game.c @@ -32,12 +32,14 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi } } + int placedWrdsAmnt = 0; + //wörter platzieren, 1 schleife = 1 wort for(int w = 0; w < wordCount; w++){ const char *word = words[w]; // *word ist immer ein wort von "words" (zeigt auf eine zeile) int len = strlen(word); - if(len > searchFieldLen) // wenn wort zu lang, nimm nächstes wort + if(len > searchFieldLen ) // wenn wort zu lang, nimm nächstes wort continue; int placed = 0; @@ -78,6 +80,7 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi } placed = 1; } + placedWrdsAmnt++; } //leere felder mit random buchstaben füllen for(int y = 0; y < searchFieldLen; y++){ @@ -86,7 +89,7 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi salad[y][x] = (rand() % 26) + 'A'; } } - return 1; + return placedWrdsAmnt; } // Prints the word salad to console diff --git a/Start_Mac/game.o b/Start_Mac/game.o index 921cd20..d916e0d 100644 Binary files a/Start_Mac/game.o and b/Start_Mac/game.o differ diff --git a/Start_Mac/input.c b/Start_Mac/input.c index 7a9b9d1..5b90610 100644 --- a/Start_Mac/input.c +++ b/Start_Mac/input.c @@ -7,23 +7,32 @@ // eine Funktion implementieren, die ein einzelnes Wort aus einer Textdatei (words.txt) einliest und als C-String zurückgibt. // Read words from file and store in 'words' array -int anzahlWoerter = 0; char zeile[500]; -int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) +int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) //words[zeilen also wörter][spalten also anzahl] { - while(anzahlWoerter <= maxWordCount && fgets(zeile, sizeof(zeile), file)){ + int anzahlWoerter = 0; + + while(anzahlWoerter <= maxWordCount && fgets(zeile, sizeof(zeile), file)){ // eine zeile char *wort = strtok(zeile, ",; \n"); while(wort != NULL && anzahlWoerter <= maxWordCount){ + if(strlen(wort) == 0){ + wort = strtok(NULL, ",; \n"); + continue; + } + strncpy(words[anzahlWoerter], wort, MAX_WORD_LEN -1); words[anzahlWoerter][MAX_WORD_LEN - 1]= '\0'; + + for(int i = 0; words[anzahlWoerter][i]; i++){ + words[anzahlWoerter][i] = toupper((unsigned char)words[anzahlWoerter][i]); //jedes wort das eingelesen wurde wird komplett gross geschrieben, unsigned damit toupper kein neg. arg bekommt (zb umlaute) + } + anzahlWoerter++; wort = strtok(NULL, ",; \n"); - } - - + } } return anzahlWoerter; } \ No newline at end of file diff --git a/Start_Mac/input.o b/Start_Mac/input.o index 7562219..0022100 100644 Binary files a/Start_Mac/input.o and b/Start_Mac/input.o differ diff --git a/Start_Mac/runTests b/Start_Mac/runTests new file mode 100755 index 0000000..1f007e5 Binary files /dev/null and b/Start_Mac/runTests differ diff --git a/Start_Mac/wordsalad_myversion b/Start_Mac/wordsalad_myversion index eeab3aa..80ec6bc 100755 Binary files a/Start_Mac/wordsalad_myversion and b/Start_Mac/wordsalad_myversion differ