summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/questions.h12
-rw-r--r--include/quiz.h34
-rw-r--r--include/utils.h30
3 files changed, 66 insertions, 10 deletions
diff --git a/include/questions.h b/include/questions.h
index 75bc751..95ce286 100644
--- a/include/questions.h
+++ b/include/questions.h
@@ -2,19 +2,19 @@
2#include <stddef.h> 2#include <stddef.h>
3 3
4typedef struct { 4typedef struct {
5 char **general; 5 char** general;
6 char **major; 6 char** major;
7 size_t general_count; 7 size_t general_count;
8 size_t major_count; 8 size_t major_count;
9} QuestionSet; 9} QuestionSet;
10 10
11/** 11/**
12 * Load questions from file. 12 * Load questions from file.
13 * Returns EXIT_SUCCESS or EXIT_FAILURE. 13 * Returns EXIT_SUCCESS or EXIT_FAILURE.
14 */ 14 */
15int load_questions(const char *filename, QuestionSet *qs); 15int load_questions(const char* filename, QuestionSet* qs);
16 16
17/** 17/**
18 * Free all allocated memory in QuestionSet. 18 * Free all allocated memory in QuestionSet.
19 */ 19 */
20void free_questions(QuestionSet *qs); 20void free_questions(QuestionSet* qs);
diff --git a/include/quiz.h b/include/quiz.h
new file mode 100644
index 0000000..db69367
--- /dev/null
+++ b/include/quiz.h
@@ -0,0 +1,34 @@
1//
2// Created by philw on 01/03/2026.
3//
4
5#pragma once
6
7#include "../include/questions.h"
8#include <stdbool.h>
9#include <stddef.h>
10#include <stdio.h>
11
12#define PERCENT_MULTIPLIER 100.0
13#define SCORE_FORMAT "Score: %zu/%zu (%.1f%%)\n"
14
15// ------------------------
16// Quiz state
17// ------------------------
18typedef struct {
19 QuestionSet questions;
20 FILE* csv;
21 unsigned int seed;
22 size_t total_answered;
23 size_t total_correct;
24 int time_limit;
25} QuizSession;
26
27// ------------------------
28// Quiz functions
29// ------------------------
30bool initialize_quiz_session(QuizSession* session);
31bool quiz_iteration(QuizSession* session);
32void print_score(size_t correct, size_t total);
33void print_final_score(const QuizSession* session);
34void cleanup_session(QuizSession* session);
diff --git a/include/utils.h b/include/utils.h
index 74c0ca1..08895c0 100644
--- a/include/utils.h
+++ b/include/utils.h
@@ -1,8 +1,30 @@
1#pragma once 1#pragma once
2
3#include <stdbool.h>
2#include <stddef.h> 4#include <stddef.h>
3 5
6/** Print a horizontal separator line */
4void print_line(void); 7void print_line(void);
5void wait_enter(const char *msg); 8
6char ask_yes_no(const char *msg); 9/** Pause until the user presses ENTER */
7void now_str(char *buf, size_t size); 10void wait_for_enter(const char* prompt);
8size_t rand_index(size_t max); 11
12/** Ask a yes/no question and return boolean */
13bool ask_yes_no(const char* prompt);
14
15/**
16 * Get the current timestamp for recording when a question was answered
17 *
18 * @param answer_time_buffer Buffer to store the formatted timestamp
19 * @param buffer_capacity Size of the buffer in bytes
20 */
21void get_answer_timestamp(char* answer_time_buffer, size_t buffer_capacity);
22
23/**
24 * Get a random question index in the quiz (thread-safe)
25 *
26 * @param seed Pointer to an unsigned int seed (per-thread)
27 * @param total_questions Number of questions in the current quiz session
28 * @return Random index in the range [0, total_questions-1]
29 */
30size_t get_random_question_index(unsigned int* seed, size_t total_questions);