g01c starts from the complete g01a terminal game. If you followed the journey path, you have it. If you are starting independently, the g01a companion repo contains the full solution.
Starting point
Your working directory must contain these files before you begin:
main.c
load.c
display.c
game.c
game.h
questions.txt
Makefile
libtci/ (your c01 build, or a copy)Verify the build:
make re
./game questions.txtThe game must run and respond to input before you add music to it.
Install aplay
aplay is part of the ALSA utilities package. Install it if it is not
already present:
sudo apt install alsa-utils
aplay --versionaplay plays WAV files from the command line. It will be the child
process that our game spawns to handle audio.
Get the WAV files
You need three royalty-free WAV files — one per tier. Search Freesound.org for tracks licensed CC0 or CC BY. What to look for:
| File | Search terms |
|---|---|
tier1.wav | quiz background loop, ambient calm, gentle suspense |
tier2.wav | suspense loop, tension music, quiz tense |
tier3.wav | dramatic climax, quiz finale, orchestral tension |
Download each track and convert it to WAV if necessary (ffmpeg -i input.mp3 output.wav). Trim each track to a clean loop of 30–90
seconds using Audacity or sox.
Create a music/ directory and place the three files there:
mkdir music
cp ~/Downloads/calm_loop.wav music/tier1.wav
cp ~/Downloads/tense_loop.wav music/tier2.wav
cp ~/Downloads/finale_loop.wav music/tier3.wavCreate the new files
Create two empty files for the music module:
touch music.c music.hAdd music.h to game.h
Open game.h and add the include for the music header immediately
after the existing system includes, before the LEVELS definition:
# include "music.h"music.h does not exist yet — the next page defines it. The include
goes in game.h so that game.c picks it up automatically (it already
includes game.h).
Update the Makefile
Add music.c to the source list:
SRCS = main.c load.c display.c game.c music.cThe %.o: %.c game.h rule already recompiles every object when
game.h changes, so no other Makefile change is needed.
Build check
The build will fail until music.c and music.h have valid content —
the compiler will complain about the missing include. Add stubs now so
the build stays clean while you work through the pages:
music.h (stub):
#ifndef MUSIC_H
# define MUSIC_H
# include <sys/types.h>
pid_t start_music(const char *path);
void stop_music(pid_t pid);
#endifmusic.c (stub):
#include "music.h"
pid_t start_music(const char *path)
{
(void)path;
return (-1);
}
void stop_music(pid_t pid)
{
(void)pid;
}make reThe game must build cleanly with zero warnings. Music will not play
yet — start_music returns -1 — but the binary works.