title: Issues with printing structs in C
body: <p>I'm incredibly new to this and have a school assignment I have to write a gradebook program that uses a custom struct to hold student IDs and grades. I have been trying unsuccessfully for days to figure out why it will not print properly, or when it does print (after a lot of shifting things around) it only prints the second set of input.</p>
  <p>The gradebook.h section is the custom structure.</p>
  <pre><code>// gradebook.h
  
  struct gradeID
  {
      int id;
      char grades[25];
  };
  </code></pre>
  <pre><code>
  // Gradebook.h is a header file to define
  // a global structure.
      
  #include &quot;gradebook.h&quot;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
      
  void sort(struct gradeID *, int);
      
  int main(void)
  {
      // Variables and structure definitions
      int ctr;
      char contInput;
      int i;
      struct gradeID grade;
      struct gradeID *identifier;
      int *temps;
      
      // Allocates 10 integers worth of memory for the program to use.
      // If there is not enough memory, the program will print an error
      // statement and terminate the program.
      temps = (int *) malloc(10 * sizeof(int));
      if (temps == 0)
      {
          printf(&quot;Not enough memory!\n&quot;);
          exit(1);
      }
      
      // Prints basic instructions for the program
      printf(&quot;\t\tGradebook Recorder\n&quot;);
      printf(&quot;Input student IDs and grades.\n&quot;);
      printf(&quot;These will be sorted by ID and printed.\n&quot;);
      
      
      /* Creates a for loop that will continue until the program
         hits the designated number of array elements. For the sake
         of expediency, I have set this amount to 10, but it can be
         changed as necessary.*/
      for(i = 0; i &lt; 10; i++)
      {
          printf(&quot;Input student ID:\n&quot;);
          scanf(&quot; %d&quot;, &amp;grade.id);
          printf(&quot;Input grade:\n&quot;);
          scanf(&quot; %s&quot;, grade.grades);
      
          // This allows early exit of the program
          printf(&quot;Do you have more grades to enter?\n&quot;);
          printf(&quot;Y/N\n&quot;);
          scanf(&quot; %c&quot;, &amp;contInput);
      
          if(contInput == 'N' || contInput == 'n')
          {
              printf(&quot;Finalizing and printing input-\n\n&quot;);
              break;
          }
      
          ctr++;
      }
      
      printf(&quot;Grades Sorted by Student ID:\n\n&quot;);
      printf(&quot;\tStudent ID: Student Grade: \n&quot;);
      
      for(i = 0; i &lt; ctr; i++)
      {
          printf(&quot;\t%d&quot;, grade.id );
          printf(&quot;\t%s&quot;, grade.grades);
      }
      
      identifier[i] = grade;
      
      return(0);
      
      free(temps);
  }
      
  void sort(struct gradeID identifier[], int counter)
  {
      int inner;
      int outer;
      struct gradeID temp;
      
      // Loops for sorting
      for(outer = 0; outer &lt; counter - 1; ++outer)
      {
          for(inner = outer + 1; inner &lt; counter; ++inner)
          {
              if(identifier[inner].id &lt; identifier[outer].id)
              {
                  temp = identifier[inner];
                  identifier[inner] = identifier[outer];
                  identifier[outer] = temp;
              }
          }
      
      }
      return;
  }
  </code></pre>