Re: How to read a flat file line by line
- From: "Default User" <defaultuserbr@xxxxxxxxx>
- Date: 8 Sep 2006 17:44:34 GMT
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
.
- References:
- How to read a flat file line by line
- From: Adi
- Re: How to read a flat file line by line
- From: mdler
- How to read a flat file line by line
- Prev by Date: Re: How do I check if a file is in use?
- Next by Date: Re: Randomly crashing program. Bad pointer to realloc?
- Previous by thread: Re: How to read a flat file line by line
- Next by thread: Re: How to read a flat file line by line
- Index(es):
Relevant Pages
|