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?

Recommended Answers

All 5 Replies

Member Avatar for iamthwee

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++; }

Yep, that fixed it. Thanks a bunch!

> 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.

Member Avatar for iamthwee

Ah never noticed the semicolon there.

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!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.