Hi,
I'm suppose to search for a string in a file ...
forexample ...
The user enters the filename ... say demofile.txt
demofile.txt contains some string like ... Leon Lewis 444-44444
Here is my code:
int main()
{
ifstream infile;
fstream datafile;
char filename[81];
char prods[8][28];
char lookup[28],*strptr=NULL;
int index,i=0;
cout<<"Enter a filename: ";
cin.getline(filename, 81);
if(!infile)
{
cout<<"Cannot Open"<<filename<<endl;
}
cout<<"\nEnter string: ";
cin.getline(lookup,28);
for(index=0;index<8;index++)
{
strptr=strstr(prods[index], lookup);
if(strptr!=NULL)
{
cout <<prods[index]<< endl;
i=i+1 ;
}
continue;
}
if(i==NULL)
cout<<"\n No string found.\n";
else
cout<<"\n"<< i <<"String Found"<<endl;
return 0;
datafile.open(filename, ios:ut);
return 0;
}
It opens the file but , it says no string found ...
Any help will be really appreciated ..