title: Struct elements as parameter in a function C programming
body: <p>Im new to programming and im having a hard time learning about allocating memory on the heap and trying to work with structs and pointer at the same time.
  This is what im trying to achieve:</p>
  
  <ul>
  <li>create a struct called student with 2 pointers elements to strings that im tring to allocate on the heap</li>
  <li>create a function that gets input from the user and saves the input in the elements of the struct on the heap</li>
  <li>create a function that prints all the values from the struct on the heap </li>
  </ul>
  
  <pre><code>#include &lt;stdio.h&gt;
  
     struct student
   { 
      char * name;
      char * course;
   };
  
  //function prototypes
  void getStudentInfo(struct student *pStu, pStu-&gt;name, pStu-&gt;course);
  void printInfo(struct student springClass[]);
  
  
  int main(){
  //create an array of 5 students
  struct student springClass[5];
  
  for(int i=0; i &lt; 5; i++)
  {
      getStudentInfo(struct student springClass[i], springClass[i].name, springClass[i].course);
  }
  
  printInfo(struct student springClass)
  
  //free memory
  free(p1);
  
  return 0;
  }
  
  
  // function that gets input from the user and saves the input in the elements of the struct on the heap
  
  void getStudentInfo(struct student *pStu, pStu-&gt;name, pStu-&gt;course)
  {
      struct student *p1 {NULL}; 
  
         //create memory on the heap
       p1 = (struct student *) malloc( 2 * (31 * sizeof(char)));  // for 1 names strings and 1 course string
  
       //get input from user
  
           printf("Enter name: ");
           fgets(p1-&gt;name, 31, stdin);
           printf("Enter course: ");
           fgets(p1-&gt;course, 31, stdin);
  
  }
  
  void printInfo(struct student springClass[])
  {
       for(int i=; i &lt; 5; i++)
       {
          printf("Student #%d Name: %s\n", i+1, springClass[i].name);
          printf("Student #%d course: %s\n", i+1, springClass[i].course);
          printf("==========================================\n");
       }
  }
  
  
  </code></pre>
  
  <p>I would really apreciate your help in anyways, thanks in advance</p>