6.Write a C++ program, which accepts any filename from command line and displays total no. of characters, total no of words and total no of lines in that file.
/*J_5_P_6
Write a C++ program, which accepts any filename from command line and
displays total no. of characters, total no of words and total no of lines in
that file.
*/
#include<iostream>
#include<fstream>
#include<string.h>
#include<cstdlib>
using namespace std;
int main()
{
int noc=0,now=0,nol=0;
FILE *fr;
char ch;
fr=fopen("abc.txt","r");
while(ch!=EOF)
{
if(ch!=' ' && ch!='\n')
noc++;
if(ch==' ')
now++;
if(ch=='\n')
{
nol++;
now++;
}
ch=fgetc(fr);
}
fclose(fr);
cout<<" -------------------------------------";
cout<<"\n Total No. of Characters : "<<noc;
cout<<"\n Total No. of Words : "<<now;
cout<<"\n Total No. of Lines : "<<nol;
return 0;
}
Comments
Post a Comment