title: allocate memory and read input from file to arrays of structures
body: <p>I have question about reading data from file to structures
  when I tried to run this code i get unhandled exception Access violation reading location 0xcccccce0, The error occur inside the getData function, Why am I getting this error, how Should I fix the code ?</p>
  
  <p>this is my input file</p>
  
  <pre><code>4
  A,10
  B,12
  C,60
  D,120
  tutorY
  </code></pre>
  
  <p>my intention in the getData function was to first read the first line to get then number 4, then use that number to allocate for student structure and then read the next four lines of the file in to student structure fields and then read the last line into tutorname feild in the TUTOR structure.</p>
  
  <p>thank in advance </p>
  
  <pre><code>    #include &lt;stdio.h&gt;
      #include &lt;stdlib.h&gt;
      #include &lt;string.h&gt;
      #include "queue.h"
      #include "stack.h"
  
      #define RECORDS_SIZE 100
      #define NAME_SIZE    20
  
      typedef struct Student
      {
          char nameStudent[NAME_SIZE];
          int  TimeIn;
          int  TimeUpdate;
      }STUDENT;
  
      typedef struct TUTOR
      {
          char nameTutor[NAME_SIZE];
          int TutorTIme;
          STUDENT *ptr;
      }TUTOR;
  
  
      QUEUE *queue1;
      STACK *stack1;
  
      void getData(STUDENT *studentArr[RECORDS_SIZE], TUTOR tutorArr[1]);
  
      int main (void)
      {
  
          STUDENT *studentArr[RECORDS_SIZE];
          TUTOR tutorArr[1];
          FILE *fp = NULL;
  
          getData(studentArr, tutorArr);
  
          return 0;
      }
  
  
      void getData(STUDENT *studentArr[RECORDS_SIZE], TUTOR tutorArr[1])
      {
          FILE *fp;
          char fileName[NAME_SIZE];
          char buffer[RECORDS_SIZE];
          int first = 0;
          int count = 1;
  
          printf("Enter file name: ");
          gets(fileName);
          fp = fopen(fileName, "r");
          if (fp == NULL)
          {
             printf("Error! The file does not exist!\n");
          }
  
          fscanf(fp,"%d",&amp;first);
          *studentArr = (STUDENT*) malloc(first*sizeof(STUDENT));
          while( fgets(buffer, first +1, fp) != NULL)
          {          
             if (count &lt;= first)
             {
                sscanf(buffer, "%[,]%d", studentArr[count]-&gt;nameStudent, studentArr[count]-&gt;TimeIn);
                printf("%s,%d", studentArr[count]-&gt;nameStudent, studentArr[count]-&gt;TimeIn);  
             }
             else
                sscanf(buffer, "%s", tutorArr[count].nameTutor);
                 count++;
          }
  
          return;
      }
  </code></pre>