C Puller
1️⃣ Install the C compiler (gcc)
Section titled “1️⃣ Install the C compiler (gcc)”Open a terminal and type:
sudo apt updatesudo apt install build-essentialThe build-essential package includes:
- gcc (C compiler)
- makeup
- basic libraries and headers
Verify:
gcc --version2️⃣ Create the source file
Section titled “2️⃣ Create the source file”For example file hello_world.c:
nano hello_world.cWrite in it:
#include <stdio.h>
int main(void) { printf("Hello, world!\n"); return 0;}Save:
- Ctrl + O
- Enter
- Ctrl + X
3️⃣ Translate the program
Section titled “3️⃣ Translate the program”In the same directory, run:
gcc hello_world.c -o hello_worldWhat happened:
- hello_world.c → sourcebook
- -o hello_world → the resulting hello_world executable
Check:
lsThere should be a file hello_world
4️⃣ Start the program
Section titled “4️⃣ Start the program”./hello_worldOutput:
Hello world!5️⃣ (Optional) Translation with warnings - recommended
Section titled “5️⃣ (Optional) Translation with warnings - recommended”For the right habits:
gcc -Wall -Wextra -Werror hello_world.c -o hello_worldThis forces you to write clean and safe C code.
6️⃣ What is good to know right from the start
Section titled “6️⃣ What is good to know right from the start”- main always returns an int
return 0;= program ended OKstdio.his the standard I/O library./tells shell to “run file from current directory”
nano read_number.c#include <stdio.h>int main(void){ int number; printf("Enter integer: "); scanf("%d",&number); printf("You entered: %d\n", number); return 0;}Recommended project structure
Section titled “Recommended project structure”If you want to keep your project professionally organized, the standard layout looks like this:
project/├── docs/ # Main project documentation│ ├── tutorials/ # Tutorials in the form of .md files│ └── examples_src/ # .md files from which you generate code├── examples/ # Resulting generated .c files (examples)├── scripts/ # Scripts (Python/Bash) that do the generation├── external/ # MD4C and other libraries├── src/ # Your source code (.c, .cpp)├── include/ # Your header files (.h)├── external/ # External libraries (e.g. md4c)│ └── md4c/│ ├── md4c.h│ └── md4c.c├── build/ # Compile outputs (ignore in git)└── CMakeLists.txt # Build configurationHint:
For folder names, always use lowercase letters and underscores or dashes instead of spaces, to avoid compatibility issues on different operating systems.