We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,985 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Very complex while loop...possible?

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,

2
Contributors
3
Replies
1 Hour
Discussion Span
1 Year Ago
Last Updated
4
Views
Question
Answered
el33t
Light Poster
27 posts since Aug 2009
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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 :)

Gribouillis
Posting Maven
Moderator
3,101 posts since Jul 2008
Reputation Points: 1,130
Solved Threads: 761
Skill Endorsements: 11

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

el33t
Light Poster
27 posts since Aug 2009
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
Question Answered as of 1 Year Ago by Gribouillis

hehe !

Gribouillis
Posting Maven
Moderator
3,101 posts since Jul 2008
Reputation Points: 1,130
Solved Threads: 761
Skill Endorsements: 11

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.1107 seconds using 2.68MB