'How to read multiple blocks of strings from text file
I'm brand new to C++, and am working on a quiz program that reads from multiple text files containing Questions that look like this, but the number of answers per question is different:
{mc} When a C program starts, the function that gets executed is called ________
- [ ] principal
- [X] main
- [ ] function
- [ ] func
- [ ] program
I assign the "{mc}" to my question type, read the rest of the line to my Question variable, Then I read each line, excluding the "[]" and assign each string to in my answers array.
I'm thinking it would be like this:
fscanf(fp, "%4s %[^\n]%*c %*s %s ", questionType, question, answer, etc...)
I don't know how to account for the number of answers being different, the max num of answers is 10. How do I read all the answers and stop before the next question? Could I turn this into a function and read each file question by question? Can I turn this into a loop so I can capture the choices in a string array?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
