Question: Using this starter code, write a c++ program to read from file and count occurrences : Example Input: ./countDucks animals02.txt Animals02.txt duck duck goose duck

Using this starter code, write a c++ program to read from file and count occurrences :

Example Input:

./countDucks animals02.txt 
Animals02.txt duck duck goose duck duck cow duck duck dog 

Example Output:

There were 6 ducks in animals02.txt 
#include // for printf()
#include // for exit(), perror()
#include // for ifstream
using namespace std;
int main(int argc, char *argv[])
{

if (argc!=2) {

// if argc is not 2, print an error message and exit

cerr << "Usage: "<< argv[0] << " inputFile" << endl;
exit(1); // defined in cstdlib
}
return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!