Sunday, August 2, 2009

This statement seems to crash my program?

I tried my program and it crashed with the good old "send error to microsoft" style crash. I commented it all out and bit by bit introduced it back and this line seems to be the culprit, any ideas? (compiling on win xp with dev c++)





while ((i != table[j]) %26amp;%26amp; (table[j])){


j++;


}

This statement seems to crash my program?
Are you sure your not getting stuck in a never ending loop with j's value constantly rising?
Reply:I sounds like an unending loop. you have to first find out the value of i, see whether there is any equal value to i in the table[j], so the program can get out of the loop.
Reply:First thing to do is reverse the conditions in while, ie, put


(table[j])%26amp;%26amp;(i!=table[j])





But that may not be enough.


You need to make sure that you dont exceed the table array boundary.





First find the maximum number of elements(MAX_TABLE) possible in table array by looking at the declaration for it and then do soemthing like below


while( (j %26lt; MAX_TABLE) %26amp;%26amp; (table[j]) %26amp;%26amp; (i!=table[j]) )





Have Fun!!
Reply:I suspect you're running into a condition where table[j] doesn't exist. Try something like





while (table[j]) {


if (i != table[j]) j++;


}
Reply:what's the value of i? if the value of i never is equal to table[j] 's value it will loop forever (or until your PC crashes 8^)
Reply:Your stopping condition isn't taking into account that j may exceed the table size before this i != table[j]) %26amp;%26amp; (table[j]))becomes false.

dried flowers

No comments:

Post a Comment