Program 9

#include<fstream>
#include<iostream>

using namespace std;
   
int main()
{
    char c;
    int countchar=1,countline=1,countword=1;
    ifstream input ;
    input.open("text2.txt",ios::in);
    while(input.get(c))
    {
        if(c == ' ' || c == ',')
        {
            countword++;
        }
        else if(c == '\n')
        {
            countline++;
            countword++;
        }
        else
        {
            countchar++;   
        }
    }
   
    cout << "characters:" << countchar << "words:" << countword << "lines:" << countline << endl;
return 0;
}

Comments