title: passing an array of structs from a function to the main program
body: <p>I have a data file of about 2500 lines. Each line contains 5 parameters.  I declare a strut out side of a routine.</p>
  
  <pre><code>typedef struct data
  {
  
  char date[9];
  char time[3];
  float price;
  float NAV;
  float percent_change;
  } _data ;
  
  void readfile(int *j, struct data *input);
  
  void readfile(int *j,struct data *input)
  </code></pre>
  
  <p>I set aside memory  to read each line of the file into an array of structs.</p>
  
  <pre><code>input = calloc(days_of_data,sizeof(*input));
  for (i = 0; i&lt; days_of_data; i++)
      input[i] = *(_data*)calloc(1,sizeof(_data));
  </code></pre>
  
  <p>and read the file.</p>
  
  <pre><code>while(fgets(line, 75, fp) != NULL)
  {      
  
      date = strtok(line,",");
      strcpy(input[i].date,date);
      time = strtok(NULL,",");
      strcpy(input[i].time, time);
      price = strtok(NULL,",");
      input[i].price = atof(price);
      NAV = strtok(NULL,",");
      input[i].NAV = atof(NAV);
      percent_change = strtok(NULL,",");
      input[i].percent_change =  atof(percent_change);
      i--;
  
  }
  </code></pre>
  
  <p>This works.  Now I want to sent the structure to the main program.</p>
  
  <pre><code>int main(int argc, const char * argv[]) {
  struct data *input;
  readfile(&amp;j, input);
  printf("%f\n",input[0].percent_change);
  }
  </code></pre>
  
  <p>This compiles but crashes on the print statement.</p>