How can I start a C program


  • Setting up directories using the text console
  • Compile a program file in the terminal window
  • Run the self-written program


All you need to learn is a simple text editor and the GCC compiler to get started. If you haven't installed these programs yet, click on the respective link. Follow the instructions for the GCC compiler, test it as described there and select a text editor.

If you have already installed a GCC compiler, please carry out the following steps to test it. Otherwise, create a directory as described, copy the source text into it and find out what it means in the next lesson.

The first step in learning to code is figuring out how and if you can compile anything at all. For this we go to the console. Under Linux we start a terminal, under MacOS the application 'Terminal' can be found under Utilities and under Windows, depending on the version, the terminal can be found under 'Start → Windows System → Command Prompt' or 'Start → All Programs → Accessories → Command Prompt' . If you want it a little faster under Windows, right-click on 'Start' and select 'Run' and enter “cmd” as the command in the dialog box that opens.

Setting up directories using the text console

In any case, we are now in the user directory with the console. Only under Windows do we first switch to the desktop so that we can get to the folder more easily:

cd desktop

The following commands apply equally to Linux, Mac and Windows: Now we create a directory with the name "c" in which we will work in the future.

mkdir c

Now we go to this directory with the command “cd”, create a directory “hworld” with “mkdir” and change to this too.

cd c mkdir hworld cd hworld

Entering a program

This is where we write our first program. To do this, we start the editor of choice and enter the following program text:

#include int main (void) {printf ("Hello \ n"); return0;}

Compile a program file in the terminal window

We save this in the “hworld” directory under the name “hworld.c”. After saving, we go back to the console window and call the compiler as follows:

gcc hworld.c

The compiler should not provide any output. If you made a mistake, you will receive corresponding error messages. So if you get output from the compiler, try to identify what is incorrectly written off. If you get stuck, please report - including the error messages - in the forum. There you will be helped.

If no messages were displayed, you have apparently successfully compiled your first program.

On Linux and Macintosh, you can use the ls command to see what is in the directory. In Windows you use the command "dir".

Run the self-written program

On Linux and Mac you will now find a file "a.out", on Windows it is called "a.exe". This is the generated program. You can run it by typing "./a.out" under Mac and Linux and "a.exe" under Windows in the terminal window and pressing the Enter key.

This should appear on the console



You have now created directories in which you can store the future programs of this tutorial. You can also create and compile a single program file and run the executable program in the terminal window.

You don't need to understand the compiled source code just yet; we'll continue with that in the next lesson.