Friday, September 20, 2019

Count number of lines, words, characters from a file in C++

A simple program that will count the number of lines, words, characters from a file using C++ programming language.

I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me in the following email address for further details.  If you want to advertise on my website kindly contact me also in my email address also. Thank you.

My email address is the following jakerpomperada@gmail.com, jakerpomperada@aol.com, and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental Philippines is  +63 (034) 4335675.

Here in Bacolod I also accepting computer repair, networking and Arduino Project development at a very affordable price.

My personal website is http://www.jakerpomperada.com.




Sample Program Output



Program Listing

#include <iostream>
#include <fstream>

using namespace std;

int main() {
   ifstream f1;
   char c;
   int numchars, numlines;

   f1.open("test.txt");

   numchars = 0;
   numlines = 0;
   system("COLOR F0");
   cout <<"\n\n";
   cout <<"\tCount number of lines, words, characters from a file";
   cout <<"\n\n";
   f1.get(c);
   while (f1) {
     while (f1 && c != '\n') {
       numchars = numchars + 1;
       f1.get(c);
     }
     numlines = numlines + 1;
     f1.get(c);
   }
   cout << "\tThe file has " << numlines << " lines and " 
     << numchars << " characters.";
   cout <<"\n\n"; 
   cout <<"\tEnd of Program";
   cout <<"\n\n";  
   system("pause");
   
}






No comments:

Post a Comment