Help to prove program
Nov 14, 2012 at 3:47pm UTC
Hello. This program is scaning first word of text.txt file and calculating how much times it repeats. All is ok, but now i need to CHANGE program, so it must calculate words such as in example. (with commas and no space)
Hello world hello hello, ,hello
so there are 4 words as the first : hello.
or
world hello world, ,world ,world world
there are 5 words as the dirst: world
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
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main() {
ifstream read("text.txt" );
int i=0, m=0;
string word, text[50000];
while (read >> word) {
text[i]=word;
i++;
if (text[0] == word){
m++;
};
};
cout <<"In text there are " << m<< " same words as first: " <<text[0] << endl;
read.close();
return 0;
}
Last edited on Nov 14, 2012 at 3:56pm UTC
Topic archived. No new replies allowed.