funktion placeRandomLetters für createWordSalad ergänzt

This commit is contained in:
Jonas Hofmann 2025-10-25 21:37:36 +02:00
parent ea373b6bad
commit f407d5a36f

View File

@ -115,6 +115,31 @@ int placeWord(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], wordPositi
return 1;
}
// Places random letters into the
// empty fields of the wordSalad
void placeRandomLetters(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen)
{
int i = 0;
int j = 0;
srand(time(NULL));
for (i = 0; i < searchFieldLen; i++)
{
for (j = 0; i < searchFieldLen; j++)
{
if (salad[i][j])
{
if ((salad[i][j] < 'A') && (salad[i][j] > 'z'))
{
salad[i][j] = rand()%('Z' - 'A' + 1) + 'A';
}
}
}
}
}
// Creates the word salad by placing words randomly and filling empty spaces
// returnes the number of sucessfully placed words
@ -143,6 +168,8 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
placedWords += placeWord(salad, currentWordPosition, currentWord, strlen(currentWord), searchFieldLen);
}
}
placeRandomLetters(salad, searchFieldLen);
return placedWords;