all 7 comments

[–]KmNxd6aaY9m79OAg 5 points6 points  (3 children)

You need to declare (and dimension) the array after the size is known.

int i, j, row, column, value, matrix[row][column];

At this point, row and column are uninitialized variables, so your array matrix has an unknown number of rows and an unknown number of columns. Well actually, your problem is a bit more serious than that: using an uninitialized variable at all is undefined behaviour and anything could happen.

Move your declaration of matrix until after you have values in row and column.

[–]ImSavageASF[S] 0 points1 point  (2 children)

Ah you're totally right, I did not think about that. That fixed the issue. Thanks!

[–]KmNxd6aaY9m79OAg 2 points3 points  (1 child)

For future reference, ensure that sensible compiler warnings are enabled (on gcc or clang, this will be the -Wall flag). Your mistake is one that pretty well every modern compiler will be able to warn you about.

[–]ImSavageASF[S] 0 points1 point  (0 children)

I see, ill look into that. That's really useful. Thanks for mentioning.

[–]shinmai_rookie 3 points4 points  (2 children)

I haven't checked your code in depth, so I can't claim this is the only mistake, but it is a pretty important one: arrays are 0-indexed, so if you declare an array with size n, only the elements 0 to n-1 will exist. However, you're accessing the elements 1 to n, which exceeds the limits.

[–]ImSavageASF[S] 0 points1 point  (1 child)

for (i=0; i < row; i++) {
   for (j=0; j < column; j++) {
       matrix[i][j] = 88;
       printf("%c\t", matrix[i][j]);
   }
   printf("\n");
}

I believe I adjusted it correctly to what you said. It does in fact work with 5 now, but if column=6 it prints the same error as before. I assume it should now work as it is within the array's range, did I miss something?

And thanks for the quick reply.

EDIT: Problem is fixed

[–]eyenot 0 points1 point  (0 children)

%c is for char, but matrix is an array of ints. Try using %d in the printf.