Hi i have a code which counts no of lines in a code. I want something like it reads a file and counts all lines in a code.
Ex:
ls cd
date
ls
ls cd
cd ls
cd ls
I want to print output like:
ls cd # 2
date # 1
ls # 1
cd ls # 2
Here is my code to count lines in a file:
#include <iostream>
#include <fstream>
using namespace std;
int main ()
{
char c;
int num=0;
ifstream is;
is.open ("1818.txt");
while (is.good())
{
c = is.get();
if (c=='\n')
num++;
}
is.close();
cout<<"Number of lines in file is "<<num<<endl;
return 0;
}
Help would be appreciated.
Thanks