Originally Posted by
c99tutorial
I think your problem is that you initially define your array like this after the user enters M and N:
So, for example if M=N=5 then we have created a 5x5 matrix (the arraz Z has 25 elements). Then later you try to do this:
It seems you are assuming that Z will resize itself which is not the case. Your choices are:
1. Make a new array on the stack with M rows and N+1 columns (not allowed according to your rule).
2. Preallocate an array with MAXROW rows and MAXCOL columns, where MAXROW and MAXCOL are "big enough".
3. Use dynamic allocation and use malloc(3), realloc(3) and free(3) as appropriate
Also it would help to break your program into functions and then just post the function which you are having trouble with. It helps for debugging and communication.