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#

  1. Visit https://code.visualstudio.com/
  2. Download the installer for your operating system
  3. Run the installer and follow the prompts
  4. Accept the default settings unless you have preferences

Linux (Ubuntu/Debian)#

sudo apt update
sudo apt install code

Linux (Fedora/RHEL)#

sudo dnf install code

Verify Installation: Open a terminal and type:

code --version

Step 2: Install a C Compiler#

Windows#

  1. Download from https://www.mingw-w64.org/
  2. Run the installer
  3. Select: Architecture: x86_64, Threads: win32, Exception: dwarf2
  4. Install to C:\mingw-w64
  5. 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 --version

Option B: Using Windows Subsystem for Linux (WSL)#

# In WSL terminal
sudo apt update
sudo apt install build-essential gdb
gcc --version

macOS#

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 gcc

Verify Installation:

gcc --version
# or for Apple's clang
clang --version

Linux (Ubuntu/Debian)#

sudo apt update
sudo apt install build-essential gdb

Verify Installation:

gcc --version

Linux (Fedora/RHEL)#

sudo dnf install gcc gdb

Step 3: Configure VSCode for C Development#

Install C/C++ Extension#

  1. Open VSCode
  2. Click on the Extensions icon (left sidebar, looks like four squares)
  3. Search for “C/C++”
  4. Install the extension by Microsoft (usually the first result)
  5. 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:

  1. Press Ctrl+K Ctrl+O (or Cmd+K Cmd+O on macOS)
  2. Select your c-programming folder
  3. Go to Run → Add Configuration
  4. 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-1

Step 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 Windows

Option 2: Using VSCode (Code Runner)

  1. Open hello.c
  2. Right-click and select “Run Code”
  3. 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+B to build
  • Press Ctrl+Shift+T to 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
  • int means it returns an integer value
    printf("Hello, C Programming!\n");
  • Prints text to the console
  • \n creates a new line
    return 0;
  • Returns 0 to indicate successful program execution
}
  • Closes the main function

Troubleshooting#

ProblemSolution
gcc: command not foundCompiler not installed or not in PATH
Permission deniedUse chmod +x hello on Linux/macOS
VSCode doesn’t recognize CReload VSCode or restart your computer
Compilation errors with strange charactersSave 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:

  1. Print multiple lines
  2. Print with different text
  3. 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!

→ Continue to Day 2