everything seems to go fine except when i get to the search. either the program runs with a runtime error or it'll just return "NO MATCH". by the way, when i put the if/else statement in the loop, it works but it also returns NO MATCH until it finds the characters.
#include<iostream>
#include<cstdlib>
#include<fstream>
#include<cstring>
#include<string>
using namespace std;
int main()
{
ifstream inFile;
char data[20][30];
char search[30];
int incVar;
inFile.open("C:/Documents and Settings/user/My Documents/CSE1384/lab5/input.txt");
for(int k=0; k<10; k++)
{
inFile.getline(data[k], 30);
cout << data[k] << endl;
}
cout << endl;
char *strPtr;
cout << "Enter for a phrase to search: ";
cin.get(search, 30);
cout << "Your search phrase is: " << search << endl;
cout << endl;
cout << endl;
cout << "Search results: " << endl;
incVar = 0;
for(int i=0; i<20; i++)
{
strPtr = strstr(data[i], search);
if(strPtr==0)
cout << "NO MATCH" << endl;
else
{
cout << data[i] << endl;
incVar++;
}
}
cout << endl;
cout << "Records found: " << incVar << endl;
cout << endl;
inFile.close();
return 0;
}