title: Windows has triggered a breakpoint - C language
body: <p>I was given an assignment to create a program that gets a 2d array, number of rows and number of columns, and then return the transposed matrix and print it, using only pointer arithmetic, no [] allowed.</p>
  
  <p>My code is working perfectly. It does indeed print the transposed matrix, but after that, i get the following message:</p>
  
  <p>Windows has triggered a breakpoint in First Assignment.exe.</p>
  
  <p>This may be due to a corruption of the heap, which indicates a bug in First Assignment.exe or any of the DLLs it has loaded.</p>
  
  <p>This may also be due to the user pressing F12 while First Assignment.exe has focus.</p>
  
  <p>The output window may have more diagnostic information.</p>
  
  <p>Can anyone help me with this? I have no idea what's wrong. This is my code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;conio.h&gt;
  #include &lt;stdlib.h&gt;
  int** allocate_matrix(int rows,int columns);
  void print_matrix(int** mat1,int rows, int columns);
  void scan_matrix(int** mat1,int rows, int columns);
  int** transpose_matrix(int** mat1, int rows, int columns);
  void main()
  {
      int** mat1;
      int** trans_mat1;
      int rows,columns;
      printf("Enter the number of rows and columns you wish to see\n");
      printf("Rows:");
      scanf("%d",&amp;rows);
      printf("Columns:");
      scanf("%d",&amp;columns);
      mat1 = allocate_matrix(rows,columns);
      scan_matrix(mat1,rows,columns);
      printf("the matrix you entered is: \n");
      print_matrix(mat1,rows,columns);
      printf("The transposed matrix is:\n");
      trans_mat1 = transpose_matrix(mat1,rows,columns);
      print_matrix(trans_mat1,columns,rows);
      getch();
      free(mat1);
      free(trans_mat1);
  }
  int** allocate_matrix(int rows,int columns)
  {
      int i;
      int** ptrmatrix;
      ptrmatrix = (int**)malloc(rows*sizeof(int*));
      for(i=0;i&lt;rows;i++)
          *(ptrmatrix+i) = (int*)malloc(columns*sizeof(int));
      return ptrmatrix;
  }
  void print_matrix(int** mat1,int rows, int columns)
  {
      int i,j;
      for(i=0;i&lt;rows;i++)
      {
          for(j=0;j&lt;columns;j++)
              printf("%d ",*(mat1+i*columns+j));
          printf("\n");
      }
  }
  void scan_matrix(int** mat1,int rows, int columns)
  {
      int i,j;
      for(i=0;i&lt;rows;i++)
      {
          printf("Enter %d values for row number %d\n",columns,i+1);
          for(j=0;j&lt;columns;j++)
              scanf("%d",(mat1+i*columns+j));
      }
  }
  int** transpose_matrix(int** mat1,int rows,int columns)
  {
      int i,j;
      int** trans_mat1;
      trans_mat1 = allocate_matrix(columns,rows);
      for(i=0;i&lt;rows;i++)
          for(j=0;j&lt;columns;j++)
              *(trans_mat1+(j*rows)+i)=*(mat1+(i*columns)+j);
      return trans_mat1;
  }
  </code></pre>