C++ Program to Count Occurrence of a Word in a Text File

This C++ program will read  a word from user and then count its total occurrence in a text file “my_data.txt”. Make sure you have already create this text file and have some text in it. Place this file in the same directory where your program source file is present.

C++ Program to Count Occurrence of a Word in a Text File

8 thoughts on “C++ Program to Count Occurrence of a Word in a Text File

    1. mukul

      #include

      using namespace std;
      int main()
      {
      char c[] = “C++ programming is not easy.”, check = ‘m’;
      int count = 0;

      for(int i = 0; c[i] != ‘\0’; ++i)
      {
      if(check == c[i])
      ++count;
      }
      cout << "Frequency of " << check << " = " << count;
      return 0;
      }

      Reply
  1. Rahul sharma

    Could you create program for calculate number of keywords in a file ?

    Reply
  2. hamza

    write a program that ask the user for the name of a file name assume the file contains a series of numbers each written on a seperate line the program should read the contents of file into an array and then display sum of these numbers
    can you please solve it for me

    Reply
  3. Hade

    Mr crazy programmer where is stdio.h header file ,because you are using gets function.

    Reply
  4. michael

    So what is strcmp ? Is it compare? When i play with c or c++ i atend to write functions that already exist. I spend all the time writing the function .

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.