simon #2

Merged
wiesendsi102436 merged 2 commits from simon into main 2025-10-31 07:20:05 +00:00
2 changed files with 40 additions and 0 deletions

View File

@ -13,11 +13,48 @@
// Creates the word salad by placing words randomly and filling empty spaces
int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], unsigned int wordCount)
{
// set seed for random number generator
srand(time(NULL));
int r, c;
//Gesamtes Feld auf 0 setzen
for (r=0; r < searchFieldLen; r++) {
for (c=0; c < searchFieldLen; c++) {
salad [r][c] = EMPTY_CHAR;
}
}
//Wörter zufällig horizontal oder vertikal platzieren
enum Richtung {HORIZONTAL,VERTIKAL}; //0;1
enum Richtung dir;
dir = (rand() % 2 == 0) ? HORIZONTAL : VERTIKAL;
//Schleife, die das Setzen für alle Wörter durchführt, Zufällig horizontal(0) oder vertikal(1), an zufällige Stelle
//Prüfen, ob das Wort von der Länge her ins Feld passt
//Felder, in denen keine Wörter stehen, werden mit zufälligen Buchstaben befüllt
for (r=0; r < searchFieldLen; r++) {
for (c=0; c < searchFieldLen; c++) {
if (salad[r][c] == EMPTY_CHAR) {
salad [r][c] = 'A' + (rand()% 26);
}
}
}
return 0;
}
// Prints the word salad to console
void showWordSalad(const char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen)
{
int r, c;
//Ausgabe des gesamten Feldes
for (r=0; r < searchFieldLen; r++) {
for (c=0; c < searchFieldLen; c++) {
printf("%c ", salad[r][c]);
}
printf("\n");
}
}

View File

@ -13,6 +13,9 @@
// Creates the word salad by placing words randomly and filling empty spaces
int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], unsigned int wordCount)
{
// set seed for random number generator
srand(time(NULL));
int r, c;
//Gesamtes Feld auf 0 setzen