Systems Programming (XMUT)
Exercise 0: Installing Code::Blocks and the first project

days Due 8 September 7 pm

Overview

This lab introduces you to the software that you will be using for your assignments, gets you to familiarise yourself with creating and running a very simple c program.

To Submit

  • hello.c

Development Workflow

The development process is pretty simple and can be summarised into four major steps:

  1. Edit source file using Code::Blocks IDE.
  2. Compile source file using Code::Blocks IDE.
  3. If bugs or warnings are present, debug and go to step 1.
  4. Execute executable output. If bugs are present, debug and go to step 1.

In Sections 1--4, we will go through each and every step of the workflow to get yourself ready to work on the first set of programming exercises.

1) Creating a project with Code::Blocks IDE

  1. Click on File → New → Project
    1.png
  2. Select Empty Project from the project category and then click on the Go button
    2.png
  3. On the Welcome message dialogue box, check the Skip this page next time checkbox. And click on the Next button.
    3.png
  4. On the next wizard screen, enter your Project title and path where to store your project. Enter any title of your project suppose HelloWorld. Choose the file path where you want to store your C files. For choosing a file path click on the ... button. And click on the Next button. It does not matter where on your computer you put this folder, in this example, the directory C:\Users\nekooei\OneDrive\Desktop\NWEN241\ is selected as the root directory.
    4.png
  5. The next screen asks you to choose a C/C++ compiler. If you have installed the GNU C/C++ compiler then you need not perform any action on this screen simply click on the Finish button. If you don't have a GNU C/C++ compiler download it before preceding the next step.
    5.png
  6. Create a new file. Click on File → New → File
    6.png
  7. From the New form template window select C/C++ source and click the Go button
    7.png
  8. If you see a welcome message, click next to skip the welcome message. Make sure you have checked the Skip this next time checkbox if you do not want to see this welcome message again.
    8.png
  9. Next, select your language from the C source window and click the Next button.
    9.png
  10. Give a name to your file and specify the location. For choosing a file path click on the ... button. Type "hello.c" as the name of the C file and click on the Save button.
    10.png11.png
  11. click Finish.
    12.png

2) Editing Source Code

Congratulations you have created your first C/C++ project in Code::Blocks. But where do I write my first C/C++ program as no editor opens after the last step? To open the code editor, navigate to the workspace area and click on the + symbol present before Sources. That will expand the sources folder. Now double click on hello.c file to open the code editor.

Type the following simple C program in the text editor as-is:
#include <stdio.h>

int main(void)
{
    printf("Hello, world\n")
}
(The above source code has intentional errors. Do not fix them at this time.)

13.png

3) Compiling

To run any C/C++ program click on Build → Build and run or simply hit F9 from your keyboard.

14.png

4) Debugging

If the compiler generates error messages, that means that your source code has bugs that you need to fix. To debug your source code, read and understand the error messages carefully.

15.png

In the above example, the error says that there is a missing semi-colon (;) before the parenthesis. It even suggests where the semi-colon should be inserted. This gives you a good clue on how to fix the code. Basically, we just have to insert a semi-colon at the end of line 5 as follows:
#include <stdio.h>

int main(void)
{
    printf("Hello, world\n");
}

Edit your source code to fix the problem and compile it again. As you can see, the compiler did not generate any error or warning message. That means that it was successful, and it generated an executable file. The Code::Blocks also shows the output screen.

16.png

right Submit your code hello.c. Make sure that you submit the .c file, not the .exe file: the .exe file is the compiled version which the markers cannot read!