All projects
Complete

20 Questions in the browser

Same C data structures, new I/O: a terminal game compiled for the browser.

Individual course project, self-directed port, Apr 2026

I started with a C course project: a learning binary decision tree, a hash table with separate chaining, undo/redo stacks, and an ncurses interface. After the assignment, I compiled the same C source with Emscripten and replaced the ncurses calls with a JavaScript bridge to an xterm.js terminal in React. The result runs in the browser, with the tree drawn live beside it.

Waiting for a keystroke

The C game loop stops and waits for keyboard input, but a browser cannot block that way. I used Emscripten Asyncify and async JavaScript shims to make the C input functions wait on promises resolved by keystrokes in xterm.js. That let the C keep its straight-line, blocking structure while the browser stayed responsive. The port made the useful boundary clear: the algorithm code was portable because it had no I/O in it.

Watching the tree grow

Every wrong guess gives the game a chance to learn a new animal, and now that change is visible beside the terminal. C sends the tree to JavaScript as JSON, and React passes it to d3-hierarchy to draw. The status bar reads node count, undo depth, and redo depth directly from C.

Try it

Answer yes or no in the terminal pane; after a wrong guess, teach it a new animal and watch the tree beside it grow.

Built with

CWebAssemblyEmscriptenAsyncifyJavaScriptReactVitexterm.jsd3-hierarchy