title: Structures and arrays in C
body: <p>I must create a program focusing on the use of structures.</p>
  
  <p>The program will ask the user to enter the number of students for whom he will later add specific information (name, surname, average grade). </p>
  
  <p>For some reason, when I start the the program, I enter the number of students i want, after that I enter the info of the first student and then the program terminates.</p>
  
  <p>Here's what I've tried.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  struct student
      {
          char *name;
          char *surname;
          float *average;
      };
  
      void inputs(struct student *a, int size);
  
  
  int main()
  {
      int size;
  
      printf("Enter the number of students: ");
      scanf("%d", &amp;size);
  
      struct student *data;
      data = (struct student *)malloc(size*sizeof(struct student));
      if(data==NULL) {
          printf("Cannot allocate memory. The program will now terminate.");
          return -1;
      }
  
      inputs (data, size);
  
      return 0;
  }
  
  void inputs(struct student *a, int size)
  {
      int j=0;
      int i;
      for(i=0; i&lt;size; i++) {
          printf("Enter the name of the student number %d: ", j+1);
          scanf("%s", a-&gt;name);
          printf("Enter the surname of the student number %d: ", j+1);
          scanf("%s", a-&gt;surname);
          printf("Enter the average grade of the student number %d: ", j+1);
          scanf("%f", a-&gt;average);
          j++;
          a++;
          }
  }
  
  
  </code></pre>