Code:
#include <frstream.h> //I don't have an up to date compiler
int main()
{
char FAQtitles[3][80];
ofstream fout("FAQfile.txt");
char dummy[80];
char searchFor[80];
int i;
char continue = 'y';
char found = 'n';
//get input for the FAQ File, you can get this from where ever you
// want.
for(i = 0; i < 3; i++)
{
cout << "enter FAQ title" << endl;
cin.getline(dummy, 80);
fout << dummy;
}
//user enters multidimensional arrays, File I/O, pointers for titles
//in FAQ file
//open FAQfile for searching;
ifstream fin("FAQfile.txt");
//allow user to search FAQ file
while(continue == 'y')
{
//obtain input to search the FAQ file for
cout << "enter title to search the FAQ file for" << end;
cin.getline(searchFor, 80);
while(found == 'n' && fin)
{
fin.getline(dummy, 80);
if(strcmp(dummy, searchFor) == 0)
{
found = 'y';
}
}
//if found is n, then search failed, if found is y the search succeeded
if(found == 'y')
{
cout << "title entered matches one of the titles in the FAQ
file" << endl;
}
else
cout << "the title " << searchFor << " not found." << endl;
//determine if user wishes to search further
cout << "enter y to continue and any other key to stop" <<endl;
cin >> continue;
}
return 0;
}
The above (uncompiled and untested) program is an (over)simplistic demonstration regarding techniques that could be used to create and search a FAQ file. Because of the limitations regarding interpretting input, however, if the user searched the above FAQ file for the title "File I/O" the search should succeed, but if they entered "using Files" it wouldn't. Likewise if they searched using "2D arrays" rather than "multidimensional arrays" it wouldn't work. Even if they searched using "Mulitdimensional arrays" or "pointer" it wouldn't work (although thoe problems could be more readily overcome). This interpretation of input rather than simple equivalency testing is the biggest technical hurdle in the overall process. The techniques to do it are well outside the scope of my knowledge.