The line responsible for choosing the random word is
chosenWordNumber = aleatoryNumber(wordsNumber);
It calls
aleatoryNumber
passing the count of found words as argument.
The
int aleatoryNumber(int maxNumber)
{
srand(time(NULL));
return (rand() % maxNumber);
}
function returns a random number between
0
and
(maxNumber-1)
, because
the
rand[
^]
C
library function returns a number between
0
and
RAND_MAX
and its result is clamped in the
0...maxNumber
range by the reminder operator.
Other solutions already explained broadly the full code behaviour.