initialize array in c

Tom3333
Tom3333 used Ask the Experts™
on
I use an array in c and i put values on it. Then i tried to initialize with zero, but unfortunately with no success. The code which i use for initialize the array is shown bellow:

 void initialize(int array[][COLUMNS])
{int i,j;
                  for(i=0;i<ROWS;i++)
                        for(j=0;j<COLUMNS;j++)
                              {
                              array[ROWS][COLUMNS]='0';      
                              }
}

what is the problem?
How to initialize this array?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
array[ROWS][COLUMNS]=0; replace  array[ROWS][COLUMNS]='0';//this is character 0 not has ASCII code 48
void initialize(int array[][COLUMNS])
{int i,j;
                  for(i=0;i<ROWS;i++)
                        for(j=0;j<COLUMNS;j++)
                              {
                              array[ROWS][COLUMNS]=0;      
                              }
}

Open in new window

ozo
Most Valuable Expert 2014
Top Expert 2015

Commented:
'0' == 48 in ASCII
did you mean 0
or you can try the line code:
 memset ( (void *) array, 0, ROWS*COLUMNS*sizeof(int));
Top Expert 2009
Commented:
Replace :

>>                               array[ROWS][COLUMNS]='0';    

with :

                              array[ i ][ j ]=0;    
ozo
Most Valuable Expert 2014
Top Expert 2015

Commented:
Yes,
>>                               array[ROWS][COLUMNS]='0';    
Is actually outside the bounds of int array[][COLUMNS]
which is undefined behavior

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial