Howdy,
I am trying to write a program that reads in a .txt file with questions and multiple choice answers. The program then needs to search the text and convert the questions into a new format and write to a new file. I don't have much so far because I am stuck. I do not understand how to read the file into something such as an array and then be able to search it so that I can reformat the questions. I need this done in order to reformat the tests for students to take in order to integrate them into WebCT. The book I purchased does not cover this unfortunately. An example of the question format is as follows.
1. A sequence of steps that must be taken to perform a task is called a(n):
a. Algorithm
b. Program
c. Binary
d. Computer
e. None of these
ANS: A
This needs to be reformatted by the program as such:
1. A sequence of steps that must be taken to perform a task is called a(n):
*a. Algorithm
b. Program
c. Binary
d. Computer
e. None of these
The * marks the correct answer now. I will greatly appreciate any help anyone can give. I don't expect anyone to write this for me but if you can show me how to do some of these things then that would be great! Thanks for any help!
int main()
{
const int SIZE = 30;
char input[30];
ifstream inFile;
cout<< "Plese make sure the test.txt file is in the same folder as the program."<<endl;
cout<< "\nWhat is the name of the test file you wish to convert? : " ;
cin >> input;
inFile.open(input);
if (!inFile) {
cerr << "Unable to open file...";
exit(1);
}
std::string buf;
std::string line;
std::ifstream in(input);
while(std::getline(in,line))
buf += line;
std::cout << "Reading input file: " << buf << "\n";
char *strPtr;
strPtr = strstr(input, "1. ");
cout << strPtr <<endl;
getch();
}