C
ComicCaper
Hi all,
I use a quiz program that accepts a text file for questions and answers
in this format:
Question
Answer1 <----is the correct answer. Quiz randomizes answers.
Answer2
Answer3
Answer4
0 <-------corresponds to which Answer is the correct one.
(4 lines of blank space then the next set.)
In order to make my life easier I created a program that will take 3
files and combine them into one using the above formatting.
Using vocab style questions I have a keyword file for the Questions, one
that has the correct answer and then one that has 3 wrong answers.
Problem: if I have 2 or 3 keywords the program works great. If I dump in
over 300 keywords the program gets stuck in a loop. I can think of only
two things that there is a hidden character in the keyword file that's
causing the problem (how do I find hidden characters?) and (for fear of
sounding stupid) that the CPU and RAM can't keep up with what is going on.
Here's my program:
/*Matt Short
*/
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
const int SIZE = 30; //setting up keywordFile;
fstream keywordFile;
char input[SIZE];
const int LINE = 400; //setting up definition file;
fstream defFile;
char def[LINE];
fstream ansFile; //setting up answer file
char ans[LINE];
ofstream quizFile("c:\\quizFile.txt"); //setting up final quiz file
keywordFile.open("c:\\keyword.txt", ios::in);
defFile.open("c:\\defFile.txt", ios::in);
ansFile.open("c:\\ansFile.txt", ios::in);
while (!keywordFile.eof())
{
keywordFile.getline(input, SIZE);
defFile.getline(def, LINE);
quizFile << input << endl << def << endl;
ansFile.getline(ans, LINE);
quizFile << ans << endl;
ansFile.getline(ans, LINE);
quizFile << ans << endl;
ansFile.getline(ans, LINE);
quizFile << ans << endl << "0" << endl << endl << endl << endl << endl;
}
keywordFile.close();
quizFile.close();
ansFile.close();
defFile.close();
return 0;
}
I use a quiz program that accepts a text file for questions and answers
in this format:
Question
Answer1 <----is the correct answer. Quiz randomizes answers.
Answer2
Answer3
Answer4
0 <-------corresponds to which Answer is the correct one.
(4 lines of blank space then the next set.)
In order to make my life easier I created a program that will take 3
files and combine them into one using the above formatting.
Using vocab style questions I have a keyword file for the Questions, one
that has the correct answer and then one that has 3 wrong answers.
Problem: if I have 2 or 3 keywords the program works great. If I dump in
over 300 keywords the program gets stuck in a loop. I can think of only
two things that there is a hidden character in the keyword file that's
causing the problem (how do I find hidden characters?) and (for fear of
sounding stupid) that the CPU and RAM can't keep up with what is going on.
Here's my program:
/*Matt Short
*/
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
const int SIZE = 30; //setting up keywordFile;
fstream keywordFile;
char input[SIZE];
const int LINE = 400; //setting up definition file;
fstream defFile;
char def[LINE];
fstream ansFile; //setting up answer file
char ans[LINE];
ofstream quizFile("c:\\quizFile.txt"); //setting up final quiz file
keywordFile.open("c:\\keyword.txt", ios::in);
defFile.open("c:\\defFile.txt", ios::in);
ansFile.open("c:\\ansFile.txt", ios::in);
while (!keywordFile.eof())
{
keywordFile.getline(input, SIZE);
defFile.getline(def, LINE);
quizFile << input << endl << def << endl;
ansFile.getline(ans, LINE);
quizFile << ans << endl;
ansFile.getline(ans, LINE);
quizFile << ans << endl;
ansFile.getline(ans, LINE);
quizFile << ans << endl << "0" << endl << endl << endl << endl << endl;
}
keywordFile.close();
quizFile.close();
ansFile.close();
defFile.close();
return 0;
}