|
From: John R. <jr...@bi...> - 2011-03-29 03:42:02
|
> As far as I know, this one of the ways of declaring a 2D matrix in C. ... The initialization happens in another nested for loop. So far you have not shown the code that establishes a value for each matrix[row][j] when 0 <= j < size and 0 <= row < size. Memcheck's complaint is about the _use_ of an uninit value in a call to printf() which appears at line 42 of matrix1.c. (And furthermore, sizeof that uninit value is 8, not 4; although this may be an artifact that is internal to _itoa_word.) As a partial clue, memcheck tells you that the space for the uninit value was created by malloc() called from line 28 of matrix1.c. Whatever is on lines 29 through 41 did not store anything into [some portion of] that space. Hint: Immediately after the malloc, printf row and matrix[row] . Immediately after each assignment in the nested 'for' loop which you claim initializes the matrix, then printf the _address_ of the entry which was intialized on that iteration. Immediately before the printf on line 42 of matrix1.c, insert another printf which prints the _address_ of anything whose value is printed by line 42. Then compare addresses. -- |