www.digitalmars.com         C & C++   DMDScript  

D - Counting lines in a file

reply "Andrew Edwards" <aedwards spamfreeamerica.com> writes:
While playing with the wc2.d example I noticed that when d accesses a file
it counts the first line as 0. Therefore if there is 10 line in the file it
will say there are only 9. This requires that we add an extra "empty" line
to your files in order to get an accurate count.

I'm thinking that the reason for this is that D uses the CR character to
identify the end of line. Could we not use both CR & EOF? This would
eliminate the need for that extra line. Minor but wbn. Thoughts?

Andrew
Jan 10 2003
parent "Walter" <walter digitalmars.com> writes:
I'll check it out. -Walter

"Andrew Edwards" <aedwards spamfreeamerica.com> wrote in message
news:avnjnl$rep$1 digitaldaemon.com...
 While playing with the wc2.d example I noticed that when d accesses a file
 it counts the first line as 0. Therefore if there is 10 line in the file

 will say there are only 9. This requires that we add an extra "empty" line
 to your files in order to get an accurate count.

 I'm thinking that the reason for this is that D uses the CR character to
 identify the end of line. Could we not use both CR & EOF? This would
 eliminate the need for that extra line. Minor but wbn. Thoughts?

 Andrew

Jan 11 2003