lauffähig und alle unit tests bestanden

This commit is contained in:
od49ukup 2025-11-02 20:33:46 +01:00
parent 332b3fa0c3
commit 300afb0db8
6 changed files with 20 additions and 8 deletions

View File

@ -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

Binary file not shown.

View File

@ -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;
}

Binary file not shown.

BIN
Start_Mac/runTests Executable file

Binary file not shown.

Binary file not shown.