title: How to create a 2D array
body: <p>Im stil a beginner in C programming and I need a little help writing a code for my C programming class
  . 
  The prompt is: 
  Input for this program is a two-dimensional array of floating point data located in a file named textfile94. The input array will contain 3 rows of data with each 
  row containing 5 columns of data. </p>
  
  <ul>
  <li>I want you to use the two-subscript method of dynamic memory allocation. </li>
  <li>Use malloc to create an array that holds pointers. </li>
  <li>Each element of that array points at another array, which is the row
  of data.</li>
  <li>Use malloc in a loop to create your rows.</li>
  <li>Then you can use two subscript operators [r][c] to get at your data
  to do the summing and averaging that the program calls for.</li>
  </ul>
  
  <p>This program calls for hard-coded height and width of the 2D array, known ahead of time (3x5, actually). Instead of writing in the literal numbers in your code, I want you to create a global constant variable to hold those dimensions, and use those in your code.</p>
  
  <p>Here is what I have so far (I'm not sure if its correct):</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  #define int rows = 3;
  #define int columns = 5;
  
  float array[rows][columns];
  
  int main(int argc, char* argv[]){
  FILE* fin;
  float x;
  int i,j;
  int* array;
  
  fin = fopen("textfile94", "r");
  fscanf("%f", &amp;x);
  array = (int*) malloc(rows*sizeof(int*));
  
  for(i=0;i&lt;rows;i++){
     for(j=0;j&lt;columns;j++)
     array[i]=(int*) malloc(columns* sizeof(int));
  }
    }
  printf("The Average values for the three rows are:%f",array[rows]);
  printf("The Average values for the five columns are:%f", array[columns]);
  
  return 0;
  }
  </code></pre>