-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquestion.h
54 lines (48 loc) · 1.65 KB
/
question.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
* AskThing: a very cursed question-and-answer engine.
*
* Copyright (c) Eason Qin, 2025.
*
* This source code form is licensed under the Mozilla Public License version
* 2.0. You may find the full text of the license in the root of the project, or
* visit the OSI website for a digital version.
*
*/
#pragma once
#include <stdbool.h>
#include <stdio.h>
#include "a_string.h"
#include "a_vector.h"
typedef struct {
a_string prompt;
a_vector answers; // a_vector of a_string (peak)
int reward;
bool case_sensitive;
} Question;
typedef struct {
a_string name;
a_vector questions; // a_vector of Question
a_string filename;
int total_score;
FILE* fp;
bool write;
} QuestionGroup;
Question question_new(a_string prompt, a_string answers, int reward,
bool case_sensitive);
Question question_new_empty(void); // create an empty question
void question_destroy(Question* q);
void question_split_answers_to_vector(
Question* q,
const char* answers); // having a vector already filled will cause UB
int question_ask(const Question* q,
int index); // negative index: no index, return: reward
QuestionGroup questiongroup_new(const char* filename);
QuestionGroup questiongroup_empty(void);
void questiongroup_add_question(QuestionGroup* g,
Question q); // will be slapped on the heap
void questiongroup_open_file(QuestionGroup* g, const char* filename);
void questiongroup_parse_file(
QuestionGroup*
g); // fills the existing questiongroup with the file contents
void questiongroup_destroy(QuestionGroup* g);
void questiongroup_ask(QuestionGroup* g);