Note that there are some explanatory texts on larger screens.

plurals
  1. POAccess violation reading location in dimensional matrix
    primarykey
    data
    text
    <p>I would like to get your help to understand and finish my program.</p> <p>This is what I have to do:</p> <blockquote> <p>"You must exercise program that: First. An absorbing two - dimensional integer arr [M] [N]. M - number of rows N - number of columns. (Matrix size was received from the user) Two. The program uses auxiliary functions "shift" moves the values ​​of the matrix to the right one place, as shown in the picture (2 entered instead of 1, 3 instead of 2, 4 instead of 3, ... 20 instead of 19, first place 20). Shift have to write a function and call her three times in the sample matrix loop .."</p> </blockquote> <p>Example picture: <img src="https://i.stack.imgur.com/i4So6.jpg" alt="enter image description here"></p> <p>error msg: <img src="https://i.stack.imgur.com/x8uiX.jpg" alt="enter image description here"></p> <p>After trying to solve the problem i gave up, i would like to get your help to understand what is wrong in my code. Is it about the memory? This is my code:</p> <pre><code>#include "stdio.h" #include "conio.h" #include "stdlib.h" #include "malloc.h" void shift (int **arr,int rows,int cols); void freemalloc ( int **arr,int rows); void main() { int **arr,cols,rows; int i,j; printf("please insert rows and columns of the matrix: "); scanf_s("%d%d",&amp;rows,&amp;cols); arr=(int **)malloc(rows*sizeof(int *)); for(i=0; i&lt;rows; i++) arr[i]=(int *)malloc(cols*sizeof(int)); for (i=0; i&lt;rows; i++) for (j=0; j&lt;cols; j++) { printf("rows %d , cols %d :\n", i, j); scanf_s("%d", &amp;arr[i][j]); } shift (arr,rows,cols); freemalloc (arr,rows); system("pause"); return ; } void shift (int **arr,int rows,int cols) { int i,j,temp=0; for(i=0; i&lt;rows ; i++ ) for( j=0 ; j&lt;cols ; j++); { temp=arr[i][j]; arr[i][j]=arr[i][cols-1]; arr[i][cols-1]=temp; } for(i=0; i&lt;rows ; i++) { for(j=0; j&lt;cols ; j++) { printf("%d ",arr[i][j]); } printf("\n"); } } void freemalloc ( int **arr,int rows) { int i; for (i=0 ; i&lt;rows ; i++) { free(arr[i]); } free(arr); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload