NO

Author Topic: warning #2238: Array index for 'char [7][7]' is out-of-bounds.  (Read 3489 times)

sannemander

  • Guest
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!



Offline Bitbeisser

  • Global Moderator
  • Member
  • *****
  • Posts: 772
Re: warning #2238: Array index for 'char [7][7]' is out-of-bounds.
« Reply #1 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

sannemander

  • Guest
Re: warning #2238: Array index for 'char [7][7]' is out-of-bounds.
« Reply #2 on: May 02, 2012, 07:25:58 PM »
Ah thx I see it now!  :-[

Offline Bitbeisser

  • Global Moderator
  • Member
  • *****
  • Posts: 772
Re: warning #2238: Array index for 'char [7][7]' is out-of-bounds.
« Reply #3 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