0

I made a dynamic 2D array using 'calloc', but when I try to fill it, I get the following error: name lookup of `j' changed for new ISO `for' scoping Here's the part of the code where it stops:

for(int j=count;j<prod;j++);
  {
        ct[j][0]=50+(j-count+1)*offset;    //error here
        count++;
  }

How do I solve this?

3
Contributors
5
Replies
6
Views
10 Years
Discussion Span
Last Post by aPPmaSTer
0

Declare int j before the for loop.

int j;
for( j=count;j<prod;j++); { ct[j][0]=50+(j-count+1)*offset; //error here count++; }

0

> for(int j=count;j<prod;j++);
It didn't fix a damn thing, you just moved the problem.
The scope of 'j' ends at that ; at the end of the line - this is a loop which does NOTHING then exists.

Had you removed this ; then the problem would have fixed itself and the loop would do what you want.

As no doubt you're about to comment that now the code "in the loop" only executes once with the wrong value.

0

Lol, me neither! And you're right, the first solution just let the thing compile, but the program didn't actually work the way it was supposed to. This fixed it for real.

Thanks!

This topic has been dead for over six months. 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.