Compare commits

...

2 Commits

Author SHA1 Message Date
od49ukup
76ecf700bb lauffähiges programm, besteht alle unit tests 2025-11-04 09:11:41 +01:00
od49ukup
db3fffe3f5 noch nicht lauffähig 2025-11-04 09:11:29 +01:00
8 changed files with 21 additions and 9 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.

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.

View File

@ -42,7 +42,7 @@ int main(int argc, char *argv[])
// error message if some words couldn't be placed
int windowWidth = 880;
if(placedWords == 1){
if(placedWords == wordCount){
startGame(wordSalad, SALAD_SIZE, words, wordCount, windowWidth);
}else{
printf("Fehler: Nicht alle Wörter konnten platziert werden.\n");

Binary file not shown.

Binary file not shown.