##Infinite loop##
Infinite loop
I just want to make one quick comment. This code here that tries to randomly place the next word:
do {
place.x = rand() % grid_size; //set to a random row
place.y = rand() % grid_size; //set to a random column
d = (arr[(p++)%10]); //get a direction according to the rule specified
} while(!check_insert(word,place,d)); //run the loop until we cant insert the word
runs the risk of running forever in an infinite loop. If you make the grid too small or you have too many words, it might be impossible to fit the next word into the grid. One simple way of fixing this would be to keep track of how many tries you have attempted and have a MAX_TRIES
constant that limits your tries. If you exceed this limit, you can either skip the word or exit with an error message.
##Infinite loop##
I just want to make one quick comment. This code here that tries to randomly place the next word:
do {
place.x = rand() % grid_size; //set to a random row
place.y = rand() % grid_size; //set to a random column
d = (arr[(p++)%10]); //get a direction according to the rule specified
} while(!check_insert(word,place,d)); //run the loop until we cant insert the word
runs the risk of running forever in an infinite loop. If you make the grid too small or you have too many words, it might be impossible to fit the next word into the grid. One simple way of fixing this would be to keep track of how many tries you have attempted and have a MAX_TRIES
constant that limits your tries. If you exceed this limit, you can either skip the word or exit with an error message.
Infinite loop
I just want to make one quick comment. This code here that tries to randomly place the next word:
do {
place.x = rand() % grid_size; //set to a random row
place.y = rand() % grid_size; //set to a random column
d = (arr[(p++)%10]); //get a direction according to the rule specified
} while(!check_insert(word,place,d)); //run the loop until we cant insert the word
runs the risk of running forever in an infinite loop. If you make the grid too small or you have too many words, it might be impossible to fit the next word into the grid. One simple way of fixing this would be to keep track of how many tries you have attempted and have a MAX_TRIES
constant that limits your tries. If you exceed this limit, you can either skip the word or exit with an error message.
##Infinite loop##
I just want to make one quick comment. This code here that tries to randomly place the next word:
do {
place.x = rand() % grid_size; //set to a random row
place.y = rand() % grid_size; //set to a random column
d = (arr[(p++)%10]); //get a direction according to the rule specified
} while(!check_insert(word,place,d)); //run the loop until we cant insert the word
runs the risk of running forever in an infinite loop. If you make the grid too small or you have too many words, it might be impossible to fit the next word into the grid. One simple way of fixing this would be to keep track of how many tries you have attempted and have a MAX_TRIES
constant that limits your tries. If you exceed this limit, you can either skip the word or exit with an error message.