title: Dynamically allocating a 2D string array
body: <p>The code seems to be on the right track however it skips out on a row and disregards the first element [0,0] pushing everything completely back by an element.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  
  int main()
  {
    char **nums;
    int i,j,k, num_cases;
    int rows, cols;
  
    printf("Enter the number of grids.\n");
    scanf("%d", &amp;num_cases);
  
  
    for(k=0;k&lt;num_cases;k++){
      printf("Test Case #%d\n", k+1);
      printf("Enter the # of rows &amp; columns separated by a space.\n");
      scanf("%d%d", &amp;rows, &amp;cols);
  
      nums = (char**)malloc(rows*sizeof(char*));
  
      for(i=0; i&lt;rows; i++){
        nums[i] = (char*)malloc(cols*sizeof(char));
      }
  
      printf("Enter your %dx%d grid of letters.\n", rows, cols);
      for(i=0; i&lt;rows; i++){
        for(j=0; j&lt;cols; j++){
          scanf("%c", &amp;nums[i][j]);
        }
      }
    }
  
    for(i=0; i&lt;rows; i++){
      for(j=0; j&lt;cols; j++){
        printf("[%d][%d] = %c\n", i, j, nums[i][j]);
      }
    }
  
    for(i=0; i&lt;rows; i++){
      free(nums[i]);
    }
  
    free(nums);
    return 0;
  }
  </code></pre>