Goals
- Set up a working C toolchain (GitHub Codespaces or local Linux with GCC + VS Code).
- Write, compile, and run simple C programs.
- Practice
printf
/scanf
format specifiers.
Lab01_C_Basics/
├─ src/
│ ├─ hello.c
│ ├─ calculator.c
│ └─ format_specifiers.c
├─ include/
├─ bin/ # compiled binaries land here
├─ .vscode/ # VS Code tasks & debug config
├─ .devcontainer/ # one-click Codespaces
├─ Makefile
├─ .gitignore
├─ LICENSE (MIT)
└─ README.md
- Push this repo to GitHub and click Code → Codespaces → Create codespace on main.
- The provided devcontainer will provision a C/C++ environment (GCC, GDB, Make).
- Open the Terminal in VS Code (inside Codespaces) and run:
make # builds all targets
./bin/hello
./bin/calculator
./bin/formats
Or use the pre-configured VS Code Tasks:
- Build All (Make) — builds all targets
- Run: Hello — builds and runs
hello
- Run: Calculator — builds and runs
calculator
- Run: Formats — builds and runs
formats
Debugging:
- Put a breakpoint in
src/hello.c
- Run Start Debugging (Hello) from the Run/Debug panel
- Install build tools:
sudo apt update && sudo apt install -y build-essential gdb
- Build with
make
:make ./bin/hello ./bin/calculator ./bin/formats
make
ormake all
— build all programsmake hello
— build Hello, Worldmake calculator
— build calculatormake formats
— build format specifier demomake clean
— remove build artifacts
- Prints a greeting and shows command-line arguments (if any).
- Simple arithmetic calculator (sum, difference, product, quotient).
- Demonstrates input validation and division-by-zero handling.
- Demonstrates key
printf
/scanf
format specifiers:- Integers:
%d
,%u
,%x
,%o
- Characters:
%c
- Floats:
%f
,%e
, precision like%.2f
- Strings:
%s
(single word),fgets
for full line input - Field width & alignment basics
- Integers:
# Build everything
make
# Run Hello (with arguments)
./bin/hello Alice 42
# Run Calculator
./bin/calculator
# Run Format Specifiers demo
./bin/formats
scanf("%d", &x)
reads an integer; always pass the address-of&x
.- After numeric
scanf
, there may be a leftover newline\n
in the buffer. Usegetchar()
or preferfgets()
+sscanf()
for robust input.
Happy hacking! 🎯