1. Program to search for a specific word in a file and count its occurrences.
#include <iostream.h>
#include <fstream.h>
#include <string.h>
#include<conio.h>
int main() {
ifstream fin("input.txt");
char word[50], line[100];
int count = 0;
cout << "Enter the word to search: ";
cin.getline(word, 50);
while (fin.getline(line, 100)) {
char *ptr = strstr(line, word);
while (ptr != NULL) {
count++;
ptr = strstr(ptr + 1, word);
}
}
fin.close();
cout << "The word '" << word << "' occurs " << count << " times." << endl;
getch();
return 0;
}