Day 1: Setting Up the Environment#
Overview#
Before we write our first C program, we need to set up a proper development environment. This includes installing a text editor, a C compiler, and configuring them to work together seamlessly.
What We’ll Do Today#
- Install Visual Studio Code (VSCode)
- Install a C compiler (GCC/Clang)
- Configure VSCode for C development
- Create our first C project structure
- Verify the setup works
Prerequisites#
- A computer (Windows, macOS, or Linux)
- Administrator/sudo access
- Internet connection for downloads
Step 1: Install Visual Studio Code#
Windows & macOS#
- Visit https://code.visualstudio.com/
- Download the installer for your operating system
- Run the installer and follow the prompts
- Accept the default settings unless you have preferences
Linux (Ubuntu/Debian)#
sudo apt update
sudo apt install codeLinux (Fedora/RHEL)#
sudo dnf install codeVerify Installation: Open a terminal and type:
code --versionStep 2: Install a C Compiler#
Windows#
Option A: Using MinGW (Recommended for Beginners)#
- Download from https://www.mingw-w64.org/
- Run the installer
- Select: Architecture: x86_64, Threads: win32, Exception: dwarf2
- Install to
C:\mingw-w64 - Add to PATH:
- Right-click “This PC” → Properties
- Click “Advanced system settings”
- Click “Environment Variables”
- Under “System variables”, find PATH, click Edit
- Add:
C:\mingw-w64\bin - Click OK and restart your computer
Verify Installation:
gcc --versionOption B: Using Windows Subsystem for Linux (WSL)#
# In WSL terminal
sudo apt update
sudo apt install build-essential gdb
gcc --versionmacOS#
Using Homebrew:
# Install Homebrew if not already installed
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Install GCC
brew install gccVerify Installation:
gcc --version
# or for Apple's clang
clang --versionLinux (Ubuntu/Debian)#
sudo apt update
sudo apt install build-essential gdbVerify Installation:
gcc --versionLinux (Fedora/RHEL)#
sudo dnf install gcc gdbStep 3: Configure VSCode for C Development#
Install C/C++ Extension#
- Open VSCode
- Click on the Extensions icon (left sidebar, looks like four squares)
- Search for “C/C++”
- Install the extension by Microsoft (usually the first result)
- Also install “Code Runner” (by Jun Han) for quick execution
Create Project Folder#
# In your terminal
mkdir ~/c-programming
cd ~/c-programming
code .This opens VSCode in the C programming folder.
Create VSCode Configuration Files#
In VSCode, create .vscode/launch.json for debugging:
- Press
Ctrl+K Ctrl+O(orCmd+K Cmd+Oon macOS) - Select your
c-programmingfolder - Go to Run → Add Configuration
- Select “C++” and choose your compiler (GCC)
This creates a .vscode/launch.json file automatically.
Step 4: Create First Project Structure#
Create the following folder structure:
c-programming/
├── .vscode/
│ ├── launch.json
│ └── tasks.json
├── day-1/
│ └── hello.c
├── day-2/
└── ...Create Day 1 Folder#
In VSCode terminal (View → Terminal):
mkdir day-1Step 5: Write Your First Program#
Create a file day-1/hello.c:
#include <stdio.h>
int main() {
printf("Hello, C Programming!\n");
return 0;
}Compile and Run#
Option 1: Using Terminal
cd day-1
gcc hello.c -o hello
./hello # On Linux/macOS
# or
hello.exe # On WindowsOption 2: Using VSCode (Code Runner)
- Open
hello.c - Right-click and select “Run Code”
- Output appears in the bottom panel
Expected Output:
Hello, C Programming!Step 6: Configure Automatic Compilation#
Create .vscode/tasks.json for easy compilation:
{
"version": "2.0.0",
"tasks": [
{
"label": "gcc build",
"type": "shell",
"command": "gcc",
"args": [
"-Wall",
"${fileDirname}/${fileBasenameNoExtension}.c",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "gcc build and run",
"type": "shell",
"command": "gcc",
"args": [
"-Wall",
"${fileDirname}/${fileBasenameNoExtension}.c",
"-o",
"${fileDirname}/${fileBasenameNoExtension}",
"&&",
"${fileDirname}/${fileBasenameNoExtension}"
],
"group": {
"kind": "test"
}
}
]
}Now you can:
- Press
Ctrl+Shift+Bto build - Press
Ctrl+Shift+Tto build and run
Understanding the Code#
Let’s break down our first program:
#include <stdio.h>- Includes the Standard Input/Output library
- Allows us to use
printf()function
int main() {- The entry point of every C program
intmeans it returns an integer value
printf("Hello, C Programming!\n");- Prints text to the console
\ncreates a new line
return 0;- Returns 0 to indicate successful program execution
}- Closes the main function
Troubleshooting#
| Problem | Solution |
|---|---|
gcc: command not found | Compiler not installed or not in PATH |
| Permission denied | Use chmod +x hello on Linux/macOS |
| VSCode doesn’t recognize C | Reload VSCode or restart your computer |
| Compilation errors with strange characters | Save file as UTF-8 encoding |
Summary#
✅ Installed VSCode
✅ Installed C compiler (GCC/Clang)
✅ Configured VSCode for C development
✅ Created first C program
✅ Successfully compiled and ran the program
Practice#
Try these variations:
- Print multiple lines
- Print with different text
- Calculate and print
2 + 2
Next Steps#
Tomorrow we’ll learn about the complete structure of C programs, input/output, and write more complex examples!