Professional Documents
Culture Documents
Code::Blocks is an all in one cross platform IDE. In this course we will use Code::Blocks IDE to
write and run all our C programs.
Open the Code::Blocks program and click on the ‘create new project’ option.
Name your project in the ‘Project Title’ box and click on ‘Next’. Choose a project title
title of your choice.
Click on ‘Finish’.
You have now created your new c project. Expand the ‘Sources’ folder and double click
on the file main.c.
The file main.c is where we will write our C programs. Code::Blocks comes with a
template in main.c which contains a skeletal C program which writes the string “Hello
World” on the console output. Study this program and see if you can figure out the
purpose of each line of code.
To run this program, we first need to build it. Do this by clicking on the ‘Build’ tab and
then selecting the ‘Build’ option.
Examine the contents of the Build Log at the bottom of the screen. This is the box which
shows you if there are any errors in your code.
To run the program press F9. The console output will be as shown below.
After executing the program you can return to the main.c file by pressing any key.
Exercises
1. Write a program which prints your name on the output console. Capture the console
output by taking a print screen of your monitor.
2. (i) Create a new C project called ‘lab1_task2’. In the main.c file, write the following
code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf("Task 2!\n");
printf("The program is now working.")
return 0;
}
(ii) Build the code and show a copy of the error message.
(iii) Correct the error and run the program. Capture the console output by taking a print
screen of your monitor and pasting it in Microsoft Word. Show this to your supervisor.