Re: How to read a flat file line by line



mdler wrote:

Hello Adi

Please don't top-post. Your replies belong following or interspersed
with properly trimmed quotes. See the majority of other posts in the
newsgroup, or:
<http://www.caliburn.nl/topposting.html>

Use fgets is the way I should do it

If you need only the string and not the control chars strip them like
this

fgets ( lineBuffer, 256, filePointer);

while(iscntrl(lineBuffer[strlen( lineBuffer)-1])
{
lineBuffer[strlen( lineBuffer)-1] = '\0';
}

Computing strlen() twice in each iteration of the loop isn't the most
efficient way of doing things. Do it once, and decrement its value as
needed.

There shouldn't even be need to check for more than '\n' unless a text
file from a different OS was transfered or something.




Brian
.



Relevant Pages