Search file.
#include <iostream> #include <fstream> #include <cstring> using namespace std; int main(int argc, char *argv[]) { if(argc!=3) { cout << "Usage: SEARCH <file> <word>\n"; return 1; } ifstream in(argv[1]); if(!in) { cout << "Cannot open input file.\n"; return 1; } char str[255]; int count=0; while(!in.eof()) { in >> str; if(!strcmp(str, argv[2])) count++; } cout << argv[2] << " found " << count; cout << " number of times.\n"; in.close(); return 0; }