Skip to main content

The C Programming Language

C has the power of assembly language and the convenience of … assembly language. -- Dennis Ritchie

C on Windows is not the best experience but virtualizing UNIX is not the solution.

Install Cygwin

Cygwin is an extensive collection of GNU and open-source tools that give access to Linux-like functionality on Windows. One of these tools, gcc, is the de facto compiler for C, which you will need during your degree.

You can either install Cygwin here or use winget:

winget install -e --id Cygwin.Cygwin

When installing Cygwin you will need to select gcc-g++, cmake, make, and gdb from the packages list.

Cygwin!

Let's test your installation!

Type gcc in your shell. You should receive an error: no input files message.

If not, then follow the below instructions:

  1. Go to the cygwin folder in your Files application.
  2. Copy the complete path to the cygwin/bin directory.
  3. Right-click "This PC" on the left sidebar.
  4. Select Properties > Advanced > Environment Variables.
  5. Navigate towards the PATH variable in System variables, click "Edit".
  6. Click "New", and paste the copied cygwin/bin directory path.

Restart your shell or restart your computer for the changes to take effect.

Configure your IDE

tip

While you can probably survive your C class without touching Terminal, we recommend using it! It not only gives you a better understanding of how a computer program is created, but also prepares you for your further modules, which almost certainly will require familiarity with the shell.

Let's use VS Code to create a simple C program!

  1. Open VS Code and create an empty file called main.c. This will be our C code source file. Such files have the .c extension!
  2. Enable language support for C by installing the C/C++ Microsoft extension.

C/C++ Microsoft extension

  1. Paste the following snippet and save the file:

    #include <stdio.h>

    int main() {
    printf("Hello, World!\n");
    return 0;
    }
  2. Now, you need to compile1 your code. Let's see how we can do it from PowerShell (or VS Code's built-in shell). Open PowerShell in the same directory as the main.c file and run the following command:

gcc -o main_executable main.c

This command will invoke gcc - compiler of the C code, compile the file called main.c and output a binary file named main_executable. 5. To run your program, simply type:

./main_executable

which should produce

> Hello, World!

Well done! 🎉 🥳

Additional Notes

  1. If you ever need to pipe something from C to another program (such as a turtle program) then you can compile your application and then run your executable in PowerShell Core with a pipe operator.
.\your_program.exe | turtle.exe
  1. If you ever need to access gcc directly then you can open the installed Cygwin Terminal.

  2. If compiling with Cygwin via the terminal results in an access denied message you can try disabling your real-time anti-virus scanning.

caution

Certain courseworks in C require that the code be compilable on UNIX systems (MacOS, Linux etc.), which Windows is not. As such, it is strongly recommended you test your code on a UNIX machine to ensure that your code functions on both machines. To access a Linux instance, you can either use virtualization, multi-booting2, or use the UCL CS lab machines (recommended).


  1. Create an executable from given source code.
  2. Installing several OSes on a single computer and choosing which one to boot.