title: Reading file data to array of structures while allocating memory dynamically
body: <p>I need help solving the code below. After the code is compiled using gcc it can be run like <code>./compiledFile inputFile.txt</code> It should take the inputFile.txt read it while allocating memory dynamically for each variable in this case name and courseID, but my code is not working. The place that I don't understand the most and need help is allocating memory, inserting data into structures and printing the data like the example given below. By the look of this code you could tell that I am a newbie to c and dynamic memory allocation and structure in all.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  
  struct people
  {
    char* name[10];
    char* courseID[15];
    int grade;
  };
  
  void printData(struct people student[], int count);
  int main(int argc, char* argv[])
  {
    FILE *in_file;
    char buffer[30];
    char *token, *del=",";
    int count=0;
  
    struct people student[20];
  
    if(( in_file = fopen(argv[1], "r")) == NULL)
    {
       printf("unable to open the file");
    }
    while (fgets(buffer, sizeof(buffer), in_file))
    {
       student = malloc(sizeof(struct people));
       token = strtok(buffer, del);
       strcpy(student[count].name, token);
       count++;
    }
    fclose(in_file);
    printData(student, count);
  }
  void printData(struct people student[], int count)
  {
    int i;
    for(i=0; i&lt;count; i++)
    {
      printf("%s", student[i].courseID);
      if (strcmp((student[i].name, student[i].courseID) &gt; 0))
      {
        printf("%s  %s", student[i].name, student[i].grade)
      }
    }
  }
  </code></pre>
  
  <p>the data.txt file has the following content separated by a comman:</p>
  
  <p><code>John,MATH 1324,90
   David,SCI 1401,88
   Omondi,MATH 1324,89
   David,MATH 1324,90
  </code></p>
  
  <p>when printed out it should look like the following:</p>
  
  <pre><code>MATH 1324
  John 90
  Omondi 89
  David 90
  
  SCI 1401
  David 88
  </code></pre>