title: Reading-File Algorithm keeps repeating data of previous lines
body: <p>I am trying to write an algorithm able to read through a file searching a specific string, which in my case is called 'label'.
  The concept is simple: Read each line until <code>EOF</code> and for each line process the content searching for a specific sequence of characters.</p>
  <p>The function:</p>
  <pre><code>char *fsearch(int fd, char *label){
      char c, buffer[500];
      int len, end, k;
  
      if((fd = open(&quot;C:\\Password-Manager\\pssw.txt&quot;, O_RDONLY, 0)) == -1){
          fprintf(stderr, &quot;Unable to locate file.&quot;);
          return NULL;
      }
      for(len = 0; read(fd, &amp;c, 1) == 1;){
          if(c == '\n')
              len++;
      }
      printf(&quot;[DEBUG]: File-Length -&gt; %d\n&quot;, len);
  
      lseek(fd, 0, SEEK_SET);
      end = k = 0;
      while(len &gt; 0){
          while(read(fd, &amp;c, 1) == 1){
              if(c == '\n')
                  break;
              buffer[k++] = c;
          }
          printf(&quot;[DEBUG]: %s\n&quot;, buffer);
          len--;
      }
  }
  </code></pre>
  <p>The function is not completed yet, next step will be parsing the content, but the problem happens right here. With a <code>printf()</code> are shown on screen the line that have been save and which will be look up late, here is the result:</p>
  <pre><code>C:\Users\Computer\Desktop\Not_Compressed_Folder\Password Managment System\1.0h&gt;init -sh
  [DEBUG]: File-Length -&gt; 3
  [DEBUG]: label0 string0
  [DEBUG]: label0 string0label1   string1ª↕
  [DEBUG]: label0 string0label1   string1label2   string2
  </code></pre>
  <p>Why is each time starting over? I supposed was something about the cursor, that jump back to the beginning each time the first while starts over. I still don't know how to fix it.
  Any kind of help will be gladly appreciated. Thanks for your time.</p>