0

Hi,

Is this a valid while loop? :

while((grid[tr][tc]=='0'||grid[tr][tc]==s[i]) && tr<row && count<strlen(s))
       { ++count;
         ++tr;
       }

Although the full program compiles fine, but sometimes my program crashes during runtime giving me a "Access violation(Segmentation Fault)" error and the debugger points to this loop statement... By the way, I'm using dev c++ ...

Regards,

Edited by el33t

2
Contributors
3
Replies
5
Views
5 Years
Discussion Span
Last Post by Gribouillis
0

I suggest to write it as

while((tr < row) && (grid[tr][tc]=='0'||grid[tr][tc]==s[i]) && (count<strlen(s)))
       { ++count;
         ++tr;
       }

If tr < row fails, grid[tr] will not be computed :)

0

WOW!! You suggestion worked!! My program no more crashes during runtime ! THANKS!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.