title: Any advice for reading in char arrays from text files in C?
body: <p>Here's my issue I'm running into.</p>
  
  <p>I'm reading in lines of text from a file, but only trying to read in lines that aren't consecutive repeats.</p>
  
  <p>Here's my regular code for reading in the lines of text.</p>
  
  <pre><code>  while (((ch = getc (fp)) != EOF))
           {
              a[j++] = ch;
           }   
            a[j] = '\0';
  </code></pre>
  
  <p>which works just fine. </p>
  
  <p>When trying to figure out how to go about the problem, I tried having a char array that would read in a line at a time, and then compare it to the previous line using strcomp. If it was a match, it would not add that line into the final char array. It looks something like this:</p>
  
  <pre><code>  while (((ch = getc (fp)) != EOF))
          {
              if (ch != '\n')
              {
              copynumber++;
              temp[j] = ch;
              }
              else 
              {
              uni = strcmp(identical, final);
                  if (uni == 0) {
                      copynumber = 0;
                  }
                  else 
                  {
                      strncpy(identical, temp, copynumber);
                      final[j] = ch;
                  }
                  j++;
              }
  
          }
            final[j] = '\0';
  </code></pre>
  
  <p>but I know this won't work for a few reasons. One, I never add the previous chars into the final array. I'm really just lost. Any help is appreciated. Thank you.</p>