generated from freudenreichan/info2Praktikum-Wortsalat
funktion placeRandomLetters für createWordSalad ergänzt
This commit is contained in:
parent
ea373b6bad
commit
f407d5a36f
@ -115,6 +115,31 @@ int placeWord(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], wordPositi
|
|||||||
return 1;
|
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
|
// Creates the word salad by placing words randomly and filling empty spaces
|
||||||
// returnes the number of sucessfully placed words
|
// 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);
|
placedWords += placeWord(salad, currentWordPosition, currentWord, strlen(currentWord), searchFieldLen);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
placeRandomLetters(salad, searchFieldLen);
|
||||||
|
|
||||||
|
|
||||||
return placedWords;
|
return placedWords;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user