|
-
March 11th, 2009, 08:05 AM
#1
How to calculate total line number of a text file
How to calculate total line number of a text file?
I have a text file. I want to get the total line number of it. Could somebody know which function should I use? Or I should write the counting code for each line?
-
March 11th, 2009, 08:10 AM
#2
Re: How to calculate total line number of a text file
Code:
int c;
while((c=fgetc(f))!=EOF)
if(c=='\n')
++num_lines;
Nobody cares how it works as long as it works
-
March 11th, 2009, 10:39 AM
#3
Re: How to calculate total line number of a text file
Use ifstream and its getline function.
For each successful getline function call increment a variable.
-
March 11th, 2009, 04:01 PM
#4
Re: How to calculate total line number of a text file
Write code like below..
Code:
CStdioFile sampleFile;
sampleFile.Open( "\\...myfile.txt", CFile::modeRead );
long length = 0;
CString temp("");
while( sampleFile.ReadString( temp ) )
{
length++;
}
// length contains your line count..
Thanks,
dwurity
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|