Count Words in Tweets (Id-1531)
Bonus Practice Sheet Winter 2018 [17-Mar-2018 to 7-Apr-2018]
Given a word ‘w’and a set of tweets in a file named as tweets.txt, write a C++ program to count the number of words in the file. Assume that the program need not bother about case of the words as the input takes care of the same.
Input Format
Word to be searched
Tweets in file
Output Format
Count of the words
Please Comment Working if the code worked to you
If you have other working codes please comment the codes enclosing with <pre> and </pre> 🙂
Example: <pre> Your Code </pre>
C++ Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | #include<fstream> #include<iostream> #include<string.h> using namespace std; int main() { fstream f; char s[100]; cin>>s; char d; f.open("tweets.txt",ios::in); int c=0; int count=0; while(!f.eof()) { f.get(d); if(d==s[c]) { c++; } else { c=0; } if(c==strlen(s)) { count++; c=0; } } cout<<count; } |