Ok well i got the digits to work finally!!!!!!
now i am working on doing a find in the file. I am asking the user to enter in a searcg string. I then need to go through my file and count how many times that word is found. this is what i have but it is returning 0 to me again. I am sure my for loop is not correct.
Code:
int count(ifstream& name, string search)
{
int count = 0;
char ch;
string words;
int wordsearch;
name >> words;
while(!name.eof())
{
name >> ch;
if(ch == '0'|| ch == '1'||ch == '2'||ch == '3'||ch == '4'||ch == '5'||ch == '6'||ch== '7'||ch == '8'||ch== '9')
{
count++;
}
name >> words;
}
cout << "# of digits: " << count << endl;
while(!name.eof())
{
int i = 0;
int wordsearch = 0;
// getline(name, words, '\n');
for(i = words.find(search, 0); i != string::npos; i = words.find(search, i))
{
wordsearch++;
i++; // Move past the last discovered instance to avoid finding same
// string
}
}
cout << "# of occurrences of " << search << ":" << wordsearch << endl;
}