noch nicht lauffähig

This commit is contained in:
od49ukup 2025-11-02 20:33:46 +01:00
parent 332b3fa0c3
commit db3fffe3f5
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 //wörter platzieren, 1 schleife = 1 wort
for(int w = 0; w < wordCount; w++){ for(int w = 0; w < wordCount; w++){
const char *word = words[w]; // *word ist immer ein wort von "words" (zeigt auf eine zeile) const char *word = words[w]; // *word ist immer ein wort von "words" (zeigt auf eine zeile)
int len = strlen(word); 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; continue;
int placed = 0; int placed = 0;
@ -78,6 +80,7 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
} }
placed = 1; placed = 1;
} }
placedWrdsAmnt++;
} }
//leere felder mit random buchstaben füllen //leere felder mit random buchstaben füllen
for(int y = 0; y < searchFieldLen; y++){ 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'; salad[y][x] = (rand() % 26) + 'A';
} }
} }
return 1; return placedWrdsAmnt;
} }
// Prints the word salad to console // 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. // 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 // Read words from file and store in 'words' array
int anzahlWoerter = 0;
char zeile[500]; 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"); char *wort = strtok(zeile, ",; \n");
while(wort != NULL && anzahlWoerter <= maxWordCount){ while(wort != NULL && anzahlWoerter <= maxWordCount){
if(strlen(wort) == 0){
wort = strtok(NULL, ",; \n");
continue;
}
strncpy(words[anzahlWoerter], wort, MAX_WORD_LEN -1); strncpy(words[anzahlWoerter], wort, MAX_WORD_LEN -1);
words[anzahlWoerter][MAX_WORD_LEN - 1]= '\0'; 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++; anzahlWoerter++;
wort = strtok(NULL, ",; \n"); wort = strtok(NULL, ",; \n");
} }
} }
return anzahlWoerter; return anzahlWoerter;
} }

Binary file not shown.

BIN
Start_Mac/runTests Executable file

Binary file not shown.

Binary file not shown.