Editor#
In the following I list the steps to setup an environment based on VSCodium, which is based on the popular text editor Visual Studio Code (VS Code). Even both are open source, I chose VSCodium, because the default extension store used by VS Code (Marketplace) contains extensions that may only be used with VS Code. The following instructions should also work with VS Code, though.
A text editor is not enough to create programs executable by our computer. Along with the text editor we will install additional tools like compiler, language server etc.
For the following tutorial I used a computer with an Intel x86-64 bit processor with Windows 11 OS build 26100. This information can be found to System Information
.
Even I tried to cater for other processors and OSs, I could not test the steps on other hardware/OS, which I donβt have access to. If the following steps do not work out for you, we can find a solution in the class. If you miss something in the steps or found an error, please create an issue or a pull request to help other students.
Installation of the editor#
We will use a package manager. On MacOS I assume you have the package manager https://brew.sh.
Open a command prompt on your OS, e.g., using β Win, then typing
cmd
on Windows.Use your package managerβs install command, e.g.,
winget
on Windows:winget install vscodium
Use Microsoft Store to install.
brew install --cask visual-studio-code
Refer to these instructions.
If you have problems with your package manager then you can try manual installation as a last resort. Bear in mind that we will use the package manager to install further software, so better make it run π.
Customizing the editor#
When you run for the first time, you should see a walkthrough for getting started.
First pick a theme that fits your environment and your taste. A study found out that a light theme is best in a well-lit environment during the day, and dark during the night.
I like
Solarized Light
, because complete white strains my eyes. You can find it when you click onBrowse Color Themes
button orSee more themes
.After choosing your theme you should see a β beside
Choose your theme
.We will leave the walkthrough without visiting other steps. We will setup other tools when we need them to understand why we need them. Click on
Go Back
on the top left corner of the tab to discard the walkthrough window. You should see theWelcome
tab.
Creating and opening a new folder#
Now we will write our first program. For each program we will code, we will use a single folder. During the semester you will write also many other programs. So think about where you will place your folder.
Tip
My recommended directory structure is:
π your-home-folder
βββ π uni
βββ π 25WS
βββ π cprog
βββ π code
βββ π hello
βββ π pi-estimator
βββ π ...
hello
and guess-the-number
are individual C projects.
Now we will create the folder hello
for our first program.
On the
EXPLORER
tab, click onOpen Folder
. The file explorer should pop up.Create the folder structure that you like as we discussed before and then
hello
.In the file explorer, click on
hello
and thenSelect folder
. A new window should pop-up with the titleDo you trust the authors of the files in this folder?
.We can trust the folder, because there is nothing we should be suspicious of. You can read about trust here.
Tick the box for
Trust the authors of all files in the parent folder 'code'
and click onYes ...
. You should see your folder open but empty on theEXPLORER
tab on the left.Hover or click with your mouse on the
EXPLORER
tab on the left. You will see the icons,
,
,
.
Click on
New File...
. A file name prompt will be activated.Enter
main.c
. In C, the root source file is namedmain.c
by convention. Why? You will understand in the next steps. After the promptmain.c
will be opened in a new tab.One of the most basic things we can do with a program is to output some characters to us β this is a way of communication between the program and us. Let us do that. Write the following code by hand to get the feeling of different symbols used in C language syntax.
Tip
Consider using the US keyboard layout for programming. Many symbols like
#
,<
,[
,;
,:
are easier to access.int main() {return 42;}
Before you save, pay attention to the
main.c
in the tabβs title. You should see a full circle similar to β«. This means that the file is not saved. Now save it using Ctrls. The circle should turn to a cross mark similar to β.
We have written code to control the behavior of a computer. This is called source code.
- source code
a plain text computer program written in a programming language
Starting a program using the terminal#
Let us try to execute our code. We usually start programs by double-clicking on them in the file explorer. We will use another approach β using the terminal.
Press CtrlShift`. A new window should open in the bottom of the editor with
TERMINAL
activated.On Windows it should show something similar to:
PS C:\Users\user\...\hello>
To execute it, write:
on Windows:
.\main.c
on Linux, macOS:
./main.c
and press Enter. What happened? Did you see any output, e.g.,
1
?on Windows: You will probably see that the operating system focus changes again to the editor tab with
main.c
β the same behavior that you would expect when you double-click on the file.on Linux, macOS: You will probably see an error message that you donβt have the permission to execute the file.
Remember that main.c
is a source code and is in a human-readable format. It is not meant to be executed by the computer. Computer only understands machine code, so we have to translate our code first.
- machine code
code consisting of machine language instructions
Why did we use a rather primitive way of starting our program? Reason: In this course we will focus on programs that input and output data using terminal, which is easier to program.
- text terminal
a serial computer interface for text entry and display