int main(int argc,char *argv[])
{
if(argc!=3) //argc should be 3 for correct execution
{
cout<<"Please enter 2 valid command-line arguments! \n";
}
else
{
ifstream the_ifile(argv[2]); //argv[2] is the filename to open
ofstream the_ofile("counter.txt", ios::app);
if (!the_ifile.IS_OPEN()) //checking to see if file opening succeeded
{
cout << "Could not open file\n";
}
else
{
int occurances=0;
int i,n;
int n = FILE.tellg(ios::end);
char string[n+1];
do //Does an infinite loop if the input file has a new
{ //line. The file should have a continuous sentence.
the_ifile.get(string,n+1);
if(strstr(string, argv[1])!=NULL)
{
occurances++;
}
the_ifile.seekg(i++);
}while(!the_ifile.eof());