title: How to pass a structure into a function to print using pointers and dynamic memory [C-Programming]
body: <p>I am trying to pass a structure into a function that will print the contents. I am asking for any sort of tips or advice.</p>
  
  <p>The struct</p>
  
  <pre><code>struct student
  {
      char *fname;
      char *lname;
      float score;
  };
  </code></pre>
  
  <p>Create prototype</p>
  
  <pre><code>void printStudents(struct student **s, int student_size);
  </code></pre>
  
  <p>Main Function</p>
  
  <pre><code>int main()
  {
      int base_number, i;
      int students;
  
      struct student *ptr;
  
      printf("Enter Number of Students: ");
      scanf("%d", &amp;base_number);
      ptr = (struct student*)malloc(base_number * sizeof(struct student));
      students = base_number;
  
      printf("\nEnter Student Information\nExample: John Smith 98.50\n\n");
  
      for(i = 0; i &lt; base_number; i++)
      {
          printf("Student %d: ", i+1);
          scanf("%s %s %f", &amp;(ptr+i)-&gt;fname, &amp;(ptr+i)-&gt;lname, &amp;(ptr+i)-&gt;score);
      }
  
      printStudents(&amp;ptr, students);
  
      return 0;
  }
  </code></pre>
  
  <p>printStudents Function</p>
  
  <pre><code>void printStudents(struct student **s, int student_size)
  {
      int i;
      struct student *temp = (struct student*)malloc(student_size * sizeof(struct student));
  
      for(i = 0; i &lt; student_size; i++)
          printf("%s %s %.2f\n", (temp+i)-&gt;fname, (temp+i)-&gt;lname, (temp+i)-&gt;score);
  }
  </code></pre>