![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Not a user?
Join Date: Sep 2007
Posts: 256
Rep Power: 2
![]() |
do while loop error or not
I have this little program (book excercise) that prints a pattern until you enter anything but Y or y. It works fine until I don't enter y or Y, then I get a runtime error stating "Run-Time Check Failure #2 - Stack around the variable 'times' was corrupted." and when I break it, it's on line 37 which is my final closing brace. During my troubleshooting, I also noticed it won't break if times is less than 10 (single digit entries). I tried using cin.get() and cin.getline() and it will still break if the number is more than 9. I notice there are still variables in the locals window for ans, times, input, and again when it reaches line 37, but I guess they aren't cleaned up until after line 37.
in the call stack, I have this "03_10_24.exe!main() Line 37 + 0xf bytes" highlighted c++ Syntax (Toggle Plain Text)
I can't figure out what the problem is, anybody see anything wrong? I don't mean with the logic of the program, but with the syntax; I'm still working the logic out. I'm thinking it has to be the way I'm handling the input into the char array, any suggestions? Last edited by Jabo; Jul 3rd, 2008 at 9:43 PM. |
|
|
|
|
|
#2 |
|
Not a user?
Join Date: Sep 2007
Posts: 256
Rep Power: 2
![]() |
Re: do while loop error or not
Big nevermind, it was with my array size, I was pulling in 3 chars into a 2 char array, duh.
|
|
|
|
|
|
#3 |
|
The Oblivious One
Join Date: May 2005
Location: Ontario, Canada
Posts: 641
Rep Power: 4
![]() |
Re: do while loop error or not
I know this isn't related to your problem, but have you considered using std::string's and C++ methods of converting strings?
I usually do something like this when I encounter this sort of thing in C++: c++ Syntax (Toggle Plain Text)
__________________
Dr. Zoidberg: [ecstatic] I'm going to a movie... with FRIENDS! |
|
|
|
|
|
#4 |
|
Not a user?
Join Date: Sep 2007
Posts: 256
Rep Power: 2
![]() |
Re: do while loop error or not
I have used the String class before, but it's been 2 years since I've done anything with C++ (in school) and I'm just going back through my book re-learning everything. At this point, the book hasn't covered strings.
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| server-infinite loop | programmingnoob | C | 19 | Oct 1st, 2006 10:52 PM |
| Value of index incorrect after loop | aznluvsmc | C | 13 | Nov 6th, 2005 9:47 PM |
| ASCII conversion loop difficulty | crmpicco | Visual Basic | 2 | May 3rd, 2005 1:55 PM |
| WinSock accept() hangs program in Do loop... | layer | C++ | 5 | Apr 29th, 2005 11:28 AM |
| Timing loop problems | badbasser98 | C++ | 11 | Mar 10th, 2005 8:30 PM |