title: What can cause istream::getline() to loop on the same line?
body: <p>I'm reading different .csv files from different sources. I am not creating those files.</p>
  
  <p>At some point when reading these files I need to skip a few lines and use this:</p>
  
  <pre><code>void skipLines(unsigned int nLines, std::ifstream&amp; file){
     char l[1024];
     for (unsigned int i = 0; i &lt; nLines; i++)
        file.getline(l, 1024);
  }
  </code></pre>
  
  <p>This worked until now for a certain file.</p>
  
  <p>The file open correctly, then I want to skip the first 5 line and I run <code>skipLines(5, file)</code>.</p>
  
  <p>By debugging, I can see that <code>l</code> correctly gets the data from the first 4 lines. When reaching the next line (which should have text), it just shows in the debugger as <code>""</code>.</p>
  
  <p>If I check the characters which are found in the that line I see the first character is <code>'\0'</code> (end of string?), the following characters are the characters that "should" be from the previous line.</p>
  
  <p>If continue to run <code>skipLines()</code> on more lines, it keeps looping on the same data. Always <code>l</code> with the same set of characters starting with <code>'\0'</code>.</p>
  
  <p>What can cause this? And how should I correctly "skip" lines when parsing a text file?</p>
  
  <p><strong>EDIT:</strong> If the content of the file is copied and pasted to new file and saved. The problem is gone. But that is not a work around I can use in this case.</p>
  
  <p>I don't want to share the exact content of the file, but it basically looks like this:</p>
  
  <pre><code>Transfers
  User,****,*****
  
  Timestamp,Type,***,Subtotal,Fees,Total,Currency,Price,Payment Method,ID,Share
  2017-06-01 10:54:42 -0700,***,0.25638772,50.0,2.00,52.0,***,195.02,***************,***54e27dd1741d3810a8e0,0
  </code></pre>
  
  <p>The line starting with Timestamp is where it loops.</p>