I want to make a multi choice question program in SML.
I have a text file whose content is structured as follows:
category1:Basic sml/sql
1-How many subsets does the power set of an empty set have?
A) One
B) Two
C) Three
D) Zero
Ans:A
2-What is the cardinality of the set of odd positive integers less than 10?
A) 20
B) 3
C) 5
D) 10
Ans:C
Each category has more than 5 questions
Each question belongs to a category
For each question there are 4 proposed answers followed by the answer on another line
I would like, to be able to retrieve and display to the user just the question (a random question) and the corresponding proposed answers. I have written this function that allows me to retrieve line by line all the content of my file. But I'm still stuck on how to unload a question-answer block.
fun getFromFile(file_name) =
let
val file = TextIO.openIn file_name
val text = TextIO.inputAll file
val _ = TextIO.closeIn file
in
String.tokens (fn c => c = #"\n") text
end
val table = getFromFile("question_file.txt");
How could I proceed? Is it possible to retrieve the lines of the file without passing them through a table first (retrieve the text directly)?
Aucun commentaire:
Enregistrer un commentaire