title: Can someone tell me why this isn't working?
body: <p>So I'm making a program to scan the name and grades of a number of students and then show me all of the students with an average of 85+.
  I'm required to use structures and the instructions say I have to dynamically allocate memory for the names with the help of the strlen function.</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;stdlib.h&gt;
  #include&lt;string.h&gt;
  
  typedef struct stud
  {
      char *name;
      int marks[4];
      float avg;
  }student;
  
  
  student* Create_Class(int);
  void Avg_Mark(student*);
  void Print_One(student*);
  
  
  int main()
  {
      int size, i;
      student *arr;
      printf("\nEnter the number of students: ");
      scanf("%d", &amp;size);
      arr = (student*)malloc(size * sizeof(student));
      arr = Create_Class(size);
      for (i = 0; i &lt; size; i++)
      {
          if ((arr + i)-&gt;avg &gt; 85)
              Print_One(arr + i);
      }
      for (i = 0; i &lt; size; i++)
          free((arr[i].name));
      free(arr);
      return 0;
  }
  
  student* Create_Class(int size)
  {
      struct stud *Arr;
      int i, j, k;
      char YourName[51];
      int length;
      Arr = (struct stud*)malloc(size * sizeof(struct stud));
      for (i = 0; i &lt; size; i++)
      {
          printf("Enter your name: ");
          scanf(" %s", YourName);
          length = strlen(YourName);
          (Arr + i)-&gt;name = (char*)malloc(length * sizeof(char));
          for (k = 0; k &lt; length; k++)
              (Arr + i)-&gt;name[k] = YourName[k];
          (Arr + i)-&gt;name[k] = '\0';
          printf("Enter your marks: ");
          for (j = 0; j &lt; 4; j++)
              scanf("%d", &amp;(Arr + i)-&gt;marks[j]);
      }
      for (i = 0; i &lt; size; i++)
          Avg_Mark(Arr + i);
      return Arr;
  }
  
  
  void Avg_Mark(student* s)
  {
      int i;
      float sum = 0;
      for (i = 0; i &lt; 4; i++)
      {
          sum += s-&gt;marks[i];
      }
      s-&gt;avg = sum / 4;
  }
  
  
  void Print_One(student* s)
  {
      printf("The average of %s is %.1f\n", s-&gt;name, s-&gt;avg);
  }
  </code></pre>
  
  <p>It seems the problem is with freeing the name field pointer in the main function.
  Can someone tell me what went wrong?
  The code itself is pretty straightforward so if anything is unclear feel free to ask and I'll try to be as detailed as possible.</p>