Quaker Runtime Error
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack microsoft visual c++ runtime library Overflow the company Business Learn more about hiring developers or posting ads with us
Runtime Error Automation Error
Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a
Runtime Error Example
community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Run-Time Check Failure #2 - Stack around the variable 'arr2' was corrupted up vote 0 http://www.quake3world.com/forum/viewtopic.php?f=10&t=44818&view=next down vote favorite int arr2[5]={5,4,3,2,1}; sortArray(arr2, 5); void sortArray(int data[], int size) { int i, j; int element; for (i = 1; i < size; i++) { element = data[i]; j = i-1; while (j >= 0 && element < data[j]) { data[j+1] = data[j]; j--; } data[j] = element; } } My function gets this error and my array look like this {5,5,5,5,5} when the function ends, why so? c http://stackoverflow.com/questions/13870208/run-time-check-failure-2-stack-around-the-variable-arr2-was-corrupted arrays sorting insertion-sort share|improve this question edited Dec 13 '12 at 23:36 tomlogic 7,06621650 asked Dec 13 '12 at 23:14 Quaker 6142928 2 During the first iteration of your for loop, after the while loop has executed, j is decremented to -1 and then used in as the index in your data array; this is the cause of your stack corruption. –ryanbwork Dec 13 '12 at 23:18 but it shouldn't do anything if j goes below 0 –Quaker Dec 13 '12 at 23:20 got it, fixed data[j] to data[j+1] –Quaker Dec 13 '12 at 23:31 1 @ryanbwork, you should enter that as an answer instead of a comment, and then Eran can mark it as accepted. –tomlogic Dec 13 '12 at 23:35 true, waiting forward for it. –Quaker Dec 13 '12 at 23:47 add a comment| 1 Answer 1 active oldest votes up vote 1 down vote accepted As stated above: during the first iteration of your for loop, after the while loop has executed, j is decremented to -1 and then used in as the index in your data array; this is the cause of your stack corruption. Some more info about stack corruption: when you reference a certain index of y
visiting this page again in a few minutes. What Can I runtime error windows Do? Please try refreshing this page again in a few minutes. We're working on solving the issue. Web server is down The web server is not returning a connection. As a result, the web page is not displaying. Ray ID: 2f719da720f502d9 Your IP address: 213.184.105.240 Error reference number: 521 CloudFlare Location: Amsterdam