Rueckgabewert von createWordSalad fuer Debugging geandert

This commit is contained in:
silvana884 2025-11-04 20:33:14 +01:00
parent b88fa9dcef
commit 5cea6d7c4d

View File

@ -15,16 +15,27 @@
// Creates the word salad by placing words randomly and filling empty spaces // 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) int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], unsigned int wordCount)
{ {
int placedChar = 0;
srand(time(NULL)); srand(time(NULL));
int usedWords[MAX_NUMBERS_OF_WORDS]; int usedWords[MAX_NUMBER_OF_WORDS];
for(int i=0; i< MAX_NUMBERS_OF_WORDS; i++){ for(int i=0; i< MAX_NUMBER_OF_WORDS; i++){
usedWords[i] = -1; usedWords[i] = -1;
} }
fillSalad(salad, searchFieldLen, words, wordCount, usedWords); fillSalad(salad, searchFieldLen, words, wordCount, usedWords);
showWordSalad(salad, searchFieldLen); showWordSalad(salad, searchFieldLen);
return 1; for(int i= 0; i < MAX_SEARCH_FIELD_LEN; i++)
{
for(int j=0; j < MAX_SEARCH_FIELD_LEN; j++)
{
if(salad[i][j] != '\0')
{
placedChar++;
}
}
}
return placedChar;
} }
// Prints the word salad to console // Prints the word salad to console
@ -52,7 +63,7 @@ int printHorizontal(unsigned int wordCount)
// returns 1, when empty spaces are left // returns 1, when empty spaces are left
int emptyPlaces(unsigned int wordCount) int emptyPlaces(unsigned int wordCount)
{ {
if(wordCount < MAX_NUMBERS_OF_WORDS) if(wordCount < MAX_NUMBER_OF_WORDS)
{ {
return 1; return 1;
} }
@ -61,7 +72,7 @@ int emptyPlaces(unsigned int wordCount)
// fills salad array with max. words from word array either horizontally or vertically // fills salad array with max. words from word array either horizontally or vertically
void fillSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], unsigned int wordCount, int usedWords[MAX_NUMBERS_OF_WORDS]) void fillSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], unsigned int wordCount, int usedWords[MAX_NUMBER_OF_WORDS])
{ {
// empties salad // empties salad
for(int i = 0; i < searchFieldLen; i++) { for(int i = 0; i < searchFieldLen; i++) {
@ -133,7 +144,7 @@ void fillSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned
} }
int whichWord(const char words[][MAX_WORD_LEN], unsigned int wordCount, int usedWords[MAX_NUMBERS_OF_WORDS]) int whichWord(const char words[][MAX_WORD_LEN], unsigned int wordCount, int usedWords[MAX_NUMBER_OF_WORDS])
{ {
int tries = 0; int tries = 0;
@ -141,7 +152,7 @@ int whichWord(const char words[][MAX_WORD_LEN], unsigned int wordCount, int used
int numWord = rand() % wordCount; // 0..wordCount-1 int numWord = rand() % wordCount; // 0..wordCount-1
int alreadyUsed = 0; int alreadyUsed = 0;
for(int f = 0; f < MAX_NUMBERS_OF_WORDS; f++){ for(int f = 0; f < MAX_NUMBER_OF_WORDS; f++){
if(usedWords[f] == numWord){ if(usedWords[f] == numWord){
alreadyUsed = 1; alreadyUsed = 1;
break; // word already used break; // word already used
@ -150,7 +161,7 @@ int whichWord(const char words[][MAX_WORD_LEN], unsigned int wordCount, int used
if(!alreadyUsed){ if(!alreadyUsed){
// Eintragen in usedWords // Eintragen in usedWords
for(int f = 0; f < MAX_NUMBERS_OF_WORDS; f++){ for(int f = 0; f < MAX_NUMBER_OF_WORDS; f++){
if(usedWords[f] == -1){ // unused if(usedWords[f] == -1){ // unused
usedWords[f] = numWord; usedWords[f] = numWord;
break; break;