title: pointer misdirection in the program
body: <p>I have got this code in C. I am getting a strange behavior when running it on GCC-4.8.1(It compiles with no warnings and errors).<br>
  When I input r and c as any integer(<strong>r=c</strong>), I get to input the dynamically allocated 2D array but, when I input r and c say, <strong>5 &amp; 4</strong> respectively(r>c), I get a don't send error in windows.I believe this maybe due to some illegal pointer indirection but I can't figure out what is it.
  Can you help me find it?<br>
  Here is the code:<br></p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;malloc.h&gt;
  #include&lt;stdlib.h&gt;
  
  int main()
  {
      int no_of_test_cases;
      int r, c;
      int i,j;
  
      printf("Enter the no of test cases:\n");
      scanf("%d", &amp;no_of_test_cases);
      printf("Enter the no of rows:\n");
      scanf("%d", &amp;r);
      printf("Enter the no of columns:\n");
      scanf("%d", &amp;c);
  
      r+=2;
      c+=2;
      //Dynamically allocate the 2D array
      char **string_pattern;
      string_pattern = (char**)malloc(r* sizeof(char*));
      if(string_pattern==NULL)
      {
          printf("Not enough memory");
          exit(0);
      }
      for(i=0; i&lt;c; i++)
      {
          string_pattern[i] = (char*)malloc(c* sizeof(char));
          if(string_pattern[i]==NULL)
          {
              printf("Not enough memory");
              exit(0);
          }
      }
      //Now lets put a wall around with the character '#'
      j=0;
      for(i=0; i&lt;r; i++)
      {
          string_pattern[i][j]='#';
      }
      j=0;
      for(i=0; i&lt;c; i++)
      {
          string_pattern[j][i]='#';
      }
      j=c-1;
      for(i=0; i&lt;r; i++)
      {
          string_pattern[i][j]='#';
      }
      j=r-1;
      for(i=0; i&lt;c; i++)
      {
          string_pattern[j][i]='#';
      }
      printf("haha");
      //Now lets input the array
      for(i=1; i&lt;r-1; i++)
      {
          for(j=1; j&lt;c-1; j++)
          {
              scanf(" %c",&amp;string_pattern[i][j]);   /*whitespace preceding the %c is to skip        
      a non whitespace character in the input buffer*/
          }
      }
      for(i=0; i&lt;r; i++)
      {
          for(j=0; j&lt;c; j++)
          {
              printf("%c",string_pattern[i][j]);
          }
          printf("\n");
      }
  
      return 0;
  }
  </code></pre>