title: Why does my program read an extra structure?
body: <p>I'm making a small console-based rpg, to brush up on my programming skills.
  I am using structures to store character data. Things like their HP, Strength, perhaps Inventory down the road. One of the key things I need to be able to do is load and save characters. Which means reading and saving structures. </p>
  
  <p>Right now I'm just saving and loading a structure with first name and last name, and attempting to read it properly.</p>
  
  <p>Here is my code for creating a character:</p>
  
  <pre><code>void createCharacter()
  {
      char namebuf[20];
  
      printf("First Name:");
  
      if (NULL != fgets(namebuf, 20, stdin))
      {
          char *nlptr = strchr(namebuf, '\n');
          if (nlptr) *nlptr = '\0';
      }
      strcpy(party[nMember].fname,namebuf);
  
  
      printf("Last Name:");
      if (NULL != fgets(namebuf, 20, stdin))
      {
          char *nlptr = strchr(namebuf, '\n');
          if (nlptr) *nlptr = '\0';
      }
      strcpy(party[nMember].lname,namebuf);
  
      /*Character created, now save */
      saveCharacter(party[nMember]);
      printf("\n\n");
      loadCharacter();
  
  }
  </code></pre>
  
  <p>And here is the saveCharacter function:</p>
  
  <pre><code>void saveCharacter(character party)
  {
      FILE *fp;
      fp = fopen("data","a");
      fwrite(&amp;party,sizeof(party),1,fp);
      fclose(fp);
  
  }
  </code></pre>
  
  <p>and the loadCharacter function</p>
  
  <pre><code>void loadCharacter()
  {
      FILE *fp;
  
      character tempParty[50];
      int loop = 0;
      int count = 1;
      int read = 2;
  
      fp= fopen("data","r");
  
      while(read != 0)
      {
          read=fread(&amp;tempParty[loop],sizeof(tempParty[loop]),1,fp);
          printf("%d. %s %s\n",count,tempParty[loop].fname,tempParty[loop].lname);
          loop++;
          count++;
      }
      fclose(fp);
  }
  </code></pre>
  
  <p>So the expected result of the program is that I input a name and last name such as 'John Doe', and it gets appended to the data file. Then it is read in, maybe something like</p>
  
  <pre><code>1. Jane Doe
  2. John Doe
  </code></pre>
  
  <p>and the program ends. </p>
  
  <p>However, my output seems to add one more blank structure to the end.</p>
  
  <pre><code>1. Jane Doe
  2. John Doe
  3. 
  </code></pre>
  
  <p>I'd like to know why this is. Keep in mind I'm reading the file until fread returns a 0 to signify it's hit the EOF. </p>
  
  <p>Thanks :) </p>