title: Segmentation Fault When Assigning Values to dynamic two dimensional array in C
body: <p>Hi I am writing a program in C, however I am getting a segmentation fault upon running my program.</p>
  
  <p>I am using gcc to compile and no warnings or errors are given at compilation time.</p>
  
  <p>I tried using gdb to trace the origin of the segfault and it directs me to the line where I am assigning data values to my two dimensional array:
  array[row][column] = datavalue;</p>
  
  <p>When I run my program stores 3 data values and then seg faults.  It should store data on 424 rows by 117 columns, but consistently it seg faults after only storing 3 data values.</p>
  
  <p>My code is as follows (with some details left out):</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;stdlib.h&gt;
  
  void allmem(float** fpdata,...);            // allocate memory header
  void stored(float** fpdata,...);            // store data header
  void countnumber(int* num1, int*num2,...);  // count header
  
  int main()   // main() function
  {
  int numberofrows = 424; // number of rows
  float** fpdata;         // two dimensional array fpdata of floats
  
  allmem(fpdata,...);     // call allocate memory function
  stored(fpdata,...);     // call function to store data
  ...
  return 0;
  } // main ()
  
  // --------------stored() function---------------
  void stored(float** fpreal,...) {
  
  FILE *fp;                  // file pointer
  float datavalue;           // variable to hold data values read
  int row;
  int column;
  
  fp = fopen("c:/file.txt","r");
  
  for(column = 0; column &lt; 117; column++) {
    for(row = 0; row &lt; 424; row++) {
      fscanf(fp, "%f,", &amp;datavalue);
      fpdata[row][column] = datavalue;
    } // for
  } // for  
  fclose(fp);
  } // stored()
  
  // ----------allmem() function----------------
  // function to allocate memory for two dimensional arrays
  // I have hard coded the values of the array sizes in, but
  // in my actual program they are calculated at run time based
  // on the size of some input files and this is done in the 
  // countnumber() function
  
  void allmem(float** fpdata,...) {
  int i = 0;
  fpdata = (float**) malloc((424)*sizeof(float*));
  fpdata2 = (float**) malloc((424)*sizeof(float*));
  ...
  for (i = 0; i&lt;424; i++) {
    fpdata[i] = (float*) malloc((117)*sizeof(float));
    fpdata2[i] = (float*) malloc((117)*sizeof(float));
  } // for
  
  } // allmem()
  </code></pre>