Andrew Peters Andrew Peters - 2 months ago 28
C Question

Process terminated with status -1073741819 mid loop?

Beginner in C and running into a problem with a function that initializes an array. Compiled in Code:Blocks 16.01 on Windows 10. Specific code I'm having issues with is:

void initAuction(float auction[2][MAXAUCTIONITEMS]) {
int i;

for (i = 0; i < MAXAUCTIONITEMS; i++) {
auction[1][i] = -1;
printf("\n%f\t%d\n", auction[1][i], i);
for (i = 0; i < MAXAUCTIONITEMS; i++) {
auction[2][i] = 0;
printf("\n\n%f\t%d", auction[2][i], i);
printf("\n%f\n", auction[2][70]);

I've set up print statements to see how far I'm getting before the crash and I make it to the second for loop but it crashes at i=140. If I change the constant (which is equal to 1000) then the highest I can set it to without crashing is i<84 oddly enough. What would cause the termination status -1073741819 mid loop when the first row initialized no problem but row 2 chooses to crash at around i=140.

I've tried searching on google and here and it seems the termination code isn't a very specific code since I've seen solutions from needing a return statement, trying to access something that doesn't exist, etc. Really lost.


You are setting elements of the array beyond its boundaries: the initial dimension of auction is 2, the only valid values for this index are 0 and 1.

You can fix and simplify the code this way:

void initAuction(float auction[2][]) {
    for (int i = 0; i < MAXAUCTIONITEMS; i++) {
        auction[0][i] = -1;
        auction[1][i] = 0;

Note that the second dimension is not part of the type of auction, it is ignored by the compiler.