Pelles C forum

C language => Beginner questions => Topic started by: sannemander on May 02, 2012, 06:55:01 PM

Title: warning #2238: Array index for 'char [7][7]' is out-of-bounds.
Post by: sannemander on May 02, 2012, 06:55:01 PM
Hi,

I donĀ“t get why I get this warning, since the array cannot be bigger then 7x7!

Code: [Select]
#include<stdio.h>

#define N 7

int main(void)
{

char CheckerBoard [N][N];
int row, col;


    for(row = 0; row < N; row++);
  for(col = 0; col < N; col++);
if ((row+col)/2 == row)
CheckerBoard[row][col] = 'B';
else
CheckerBoard[row][col] = 'R';




return 0;

}

I  also tried it with a while loop but kept the same error!

grtz!


Title: Re: warning #2238: Array index for 'char [7][7]' is out-of-bounds.
Post by: Bitbeisser on May 02, 2012, 07:24:11 PM
Very simple error! 

Take a very close look at the (end of the) for() loop statements...  ;)

Ralf
Title: Re: warning #2238: Array index for 'char [7][7]' is out-of-bounds.
Post by: sannemander on May 02, 2012, 07:25:58 PM
Ah thx I see it now!  :-[
Title: Re: warning #2238: Array index for 'char [7][7]' is out-of-bounds.
Post by: Bitbeisser on May 02, 2012, 07:31:30 PM
Ah thx I see it now!  :-[
You're welcome!  8)

Just as a tip, which helps IMHO to avoid such quirks, is to getting used to start writing such a statement as a template like
Code: [Select]
for(;;){};and then fill out the "inner" parts.
The braces help to determine the scope of the for() loop and also in placing the terminating semicolon in the right place...

Ralf