Sample – count number of characters and lines in a file
by Nideesh C on February 8, 2011 · 0 comments
in C++
#include <iostream.h>
#include <fstream.h>
int main () {
ifstream f1;
char c;
int numchars, numlines;
f1.open(“test”);
numchars = 0;
numlines = 0;
f1.get(c);
while (f1) {
while (f1 && c != ‘\n’) {
numchars = numchars + 1;
f1.get(c);
}
numlines = numlines + 1;
f1.get(c);
}
cout << “The file has ” << numlines << ” lines and ”
<< numchars << ” characters” << endl;
return(0);
}
Not Satisfied ? Just search & get the result
Related posts:
- Sample program (multiplication using addition)
- Stereo FM Transmitter Using I.C – BH1417
- Little about system file types
Tagged as:
c programming examples,
c programming reference,
c tutorial,
c++ program examples,
C++ Programming,
count number of characters and lines in a file,
learning c++,
programming languages,
programming languages c,
sample c++ programs,
sample cods
Me, freelance system administrator having the qualification of Diploma in Electronics & Tele-communication + MCSE + CCNA + CST + 5 years of experience in IT field.
If you like This post, you can follow TheOnlineTutorials on Twitter.
Contact me Via email: support@theonlinetutorials.com
Subscribe to feed via Feed or EMAIL to receive instant updates.
Legal Disclaimer:All information found on the site is without any implied warranty of fitness for any purpose or use whatsoever. Content author/site administrator is not responsible for any loss occurred due to mistakes in this tutorial. Use this tutorial website at your own risk.