C Why can't my fgets() read line properly when writing with \n after words
<p>This is a bit difficult to articulate but what I would like is for my commented out fprintf function to be commented in and my other two print functions commented out (In my add_to_white_list function). </p>

<p>However, when I write to the file in that way (with the \n after the word) something goes wrong with my fgets line reader in the remove_from_white_list function. In debugging my fgets reads the first line and then seems to be blank after.</p>

<p>This if very confusing to me because everything mostly works as is and there are still newline characters after all my words except for the last word in the file.  </p>

<pre><code>void add_to_white_list(char* ip) {
  FILE *fp;
  fp = fopen("../app/whitelist.txt", "r+");

  if (!(getc(fp) &lt; 0)) {
    fseek(fp, 1, SEEK_END);
    fputs("\n", fp);
  }

  fprintf(fp, "%s", ip);
  //fprintf(fp, "%s\n", ip);

  fclose(fp);
}

void remove_from_white_list(char* ip) {
  FILE *fp;
  FILE *fp_temp;
  fp = fopen("../app/whitelist.txt", "r");
  fp_temp = fopen("../app/temp.txt", "w+");

  char buff[255];
  int matched = 0;

  while (fgets(buff, 255, fp) != NULL) {
    strip(buff);
    if (!(strcmp(buff, ip) == 0)) {
        fprintf(fp_temp, "%s\n", buff);
    } else {
      matched = 1;
    }
  }

  fclose(fp);
  fclose(fp_temp);

  if (matched == 0) {
    printf("Please supply an ip address that is currently listed on the whitelist\n");
  } else {
    rename("../app/temp.txt", "../app/whitelist.txt");
  }
}
</code></pre>

<p>*I didn't include my strip function but it removes \n</p>