I want to analyze the content of a text file & search for a string in the file.
It is assumed a sentence is terminated by a , . ; ? !

This is what i have so far

#include <iostream>
#include <fstream>

using namespace std;

int main()
{
    ifstream fin;
    char filename[30];
    char buffer[255];
    size_t found;
    string s;
    string str;
    size_t found;
    
    cout << "Enter filename (including .txt): ";
    cin >> filename;
    cout <<"Word to search for: ";
    cin >> buffer;

    fin.open(filename);
    if (!fin.good())
    {
        cout << "File not found" << endl;
		return 1;
    }

	while(!fin.eof())
	{
        found=str.find_first_of(".,?;!");
        // use getline to read entire line 
  
       getline(fin, s);
        cout << found << endl;
        
    }
    
    fin.close();    
    system("pause");
    return 0;
}

Can someone help me please

looks good :)

that loop is backwards

while( getline( fin, s) )
{
    found=str.find_first_of(".,?;!");
   // That might find a sentence, but does not mean its the entire
   // sentence -- part of the sentence may have been on the previous
   // line -- like this comment.
}

while(!fin.eof()) , before testing for EOF you should have performed at least one read operation (read this), so this would be a correct way to do it:

[B]getline(fin, s);[/B]
while(!fin.eof())
{
  getline(fin, s);
  cout << found << endl;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.