A terminal flashcard quiz program written in C.
This is a learning project, built while following Beej's Guide to C Programming (up to chapter 9).
Use at your own risk.
- Loads a deck of flashcards from a plain text file
- Shuffles the deck (unless
--no-shuffleis given) - Quizzes you one card at a time: shows the question, waits for Enter, then reveals the answer and asks whether you got it right
- Repeats the cards you got wrong until you've cleared the deck
- Shows your score and (optionally) logs the session to
flash.log - On startup, summarises your past sessions for that deck (number of sessions, average and best score)
makeflash [--no-shuffle] [-h|--help] <deck-file>Examples:
flash decks/cards.txt
flash --no-shuffle ~/deck.txtCards are plain text. A question line, an answer line, then a --- separator:
What does sizeof return for an array parameter inside a function?
The size of the pointer it decayed to, not the original array size.
---
Why does fgetc return int rather than char?
So EOF (typically -1) is distinguishable from any valid character value.
---
Blank lines are ignored, and leading/trailing whitespace is trimmed. A deck can
hold up to 100 cards (MAX_DECK_SIZE).
flash.c entry point
lib/cards.c deck loading, shuffling, quizzing a single card
lib/score.c scoring, session logging, startup summary
lib/term.c drawing cards centered in the terminal, reading y/n & Enter
lib/alt_buf.c alternate screen buffer handling
lib/utils.c argument parsing, line validation and sanitization
flash.log log of past sessions
- The program switches to the terminal's alternate screen buffer on start
(the same trick
vimandlessuse) and restores your screen on exit via anatexithandler, so your scrollback is left untouched. - Cards are drawn centered using the terminal size from
ioctl(TIOCGWINSZ). - Session history is parsed back out of
flash.logwithstrtokto compute the startup summary.
-
If the program is killed abruptly (e.g.
Ctrl-C), the cleanup that re-shows the cursor never runs, so your terminal cursor stays hidden. Restore it with:printf '\033[?25h'