Last active
February 5, 2018 00:35
-
-
Save bha159/0f8be78770166f5796267af30e02783b to your computer and use it in GitHub Desktop.
A c++ program to calculate occurence of a word in a text file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream.h> | |
#include<fstream.h> | |
#include<string.h> | |
using namespace std; | |
int main() | |
{ | |
ifstream fin("my_data.txt"); //opening text file | |
int count=0; | |
char ch[20],word[20]; | |
cout<<"Enter a word to count:"; | |
gets(word); | |
while(fin) | |
{ | |
fin>>ch; | |
if(strcmp(ch,word)==0) | |
count++; | |
} | |
cout<<"Occurrence="<<count<<"n"; | |
fin.close(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment