PDA

View Full Version : Input text file to array help



Deadvacahead
12-06-2007, 07:56 PM
Howdy, I am trying to write a program and I have very little experience in doing this. I have multiple choice tests that are .text files. These tests are in the wrong format and I need to create a program to convert them. 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 topic unfortunately. An example of the question format the text files are currently in is as follows:

*. Question bla bla bla bla bla
a. bla bla bleh
b. ble ble bla
c. bla
d. bla bla ble ble blah
ANS: A

As you can see, the text file lists the answers by showing ANS: A and such at the end of each multiple choice question. This format however is bad and is not compatible with Respondus, the software I'm using to import my tests into. The Respondus program requires the questions to look like this: using an asterisk to mark the correct answer rather than the first method.

*. Question bla bla bla bla bla
*a. bla bla bleh
b. ble ble bla
c. bla
d. bla bla ble ble blah

The program needs to take questions from the input text file and convert them from the first question example into the format of the second example all inside a new text file created by the program.

Here is my code thus far:

int main()
{
const int SIZE = *0;
char input[*0];
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(*);
}
std::string buf;
std::string line;
std::ifstream in(input);
while(std::getline(in,line))
buf += line;
std::cout << "Reading input file: " << buf << "\n";

getch();
}

If you would like to compile the code just create a normal text file and name it whatever you want. Make sure its in the same folder as the program. The program runs, asks for the name of the test to open and that's about it for right now. I don't know the next step to get the test into an array so that I may focus on how to possibly search the array or string and have the function reformat the text file to the Respondus format in a new text file. As I said, I am pretty new to all this and basically winging it from a book. I apologize for the length of this post and for any trouble in understanding what I need. If anyone can help guide me in the right direction I would greatly appreciate it. Thanks for any time and effort to help out!