0% found this document useful (0 votes)
2 views15 pages

Programming in C- Set_up Environment

To set up a programming environment for C, you need a text editor and a compiler, with Code Blocks recommended as an IDE that includes the GCC compiler. The document outlines steps for installing Code Blocks on Windows and also provides instructions for installing a C compiler on mobile devices. Additionally, it explains the basic structure of a C program using a 'Hello World' example and details the process for compiling and executing the program.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views15 pages

Programming in C- Set_up Environment

To set up a programming environment for C, you need a text editor and a compiler, with Code Blocks recommended as an IDE that includes the GCC compiler. The document outlines steps for installing Code Blocks on Windows and also provides instructions for installing a C compiler on mobile devices. Additionally, it explains the basic structure of a C program using a 'Hello World' example and details the process for compiling and executing the program.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

Setting up the programming environment.

To create and run programs you need two things:

1. Text editor
2. Compiler

A text editor is where you write your programs. A compiler translates your program into a
binary stream of 1s and 0s which computer understands. So whenever you compile a
program, the compiler creates a new binary file called executable (having .exe extension in
Windows) which computer can execute.

Steps you need to follow while writing C programs.

1. Create a program
2. Compile program
3. Run program

You can create your programs using your default text editor like Notepad in Windows or vim
in Linux, but to make things easy we will install a cross-platform IDE(Integrated
Development Environment) called Code Blocks.

Why use an IDE?

IDE allows you to create, compile and run programs from a single environment. Code Blocks
comes with a compiler called GCC to compile C and C++ programs. If you are not using IDE
then you need to create the program using your text editor. Then to compile the program you
need to open command prompt or terminal and type some commands. We will first learn how
to write a simple program using an IDE, then I will show you how you can create programs
using your text editor and compile it using GCC compiler.
Installing Code Blocks in Windows

1. Go to http://www.codeblocks.org/downloads/26 and scroll down a little under Section


"Windows XP / Vista / 7 / 8.x / 10:" select "codeblocks-16.01mingw-nosetup.zip".

It is crucial for you to select MinGW setup because this will install the GCC compiler
on your system.

2. After downloading double click on the setup to run it and you will be presented with
the following window. Click next to continue.
3. Accept the license agreement and click next.

4. In the next window, Code Blocks will ask you to select components you want to
install. Select Full Installation, it will look something like this:
Make sure "MinGW Compiler Suite" is selected because this option will install GCC
on your system.

5. Select the destination folder (keep it to default) and click next.


6. The installer will proceed to complete the installation.

7. After completing the installation, Code Blocks will prompt you to run it.
8. Click no and then click on the Next button.

Installing a C compiler on the mobile phone


A C compiler can also be installed on the mobile device to enable students who do not have a
laptop to write and compile their code/programs. The following steps can be followed:
1. Open the google play store on your mobile device and ensure you have internet
connection.
2. In the search box type “C compiler” and several applications will appear when the
search is complete as shown in the image below.
3. Tap the app named “coding C- The offline compiler by Kvass Yu” then install it.
After the installation is complete, click open to launch the application.
4. The application opens the IDE with a simple c program that you can compile.
5. Click run to compile the program. The output will be presented after a short while.
You can go back to the IDE by pressing enter in your mobile device.
C programming language
Before we study the basic building blocks of the C programming language, let us look at a
bare minimum C program structure so that we can take it as a reference in the upcoming
chapters.

Hello World Example

A C program basically consists of the following parts −

 Preprocessor Commands
 Functions
 Variables
 Statements & Expressions
 Comments
Let us look at a simple code that would print the words "Hello World" −
#include <stdio.h>

int main() {
/* my first program in C */
printf("Hello, World! \n");

return 0;
}
Let us take a look at the various parts of the above program −
 The first line of the program #include <stdio.h> is a preprocessor command, which
tells a C compiler to include stdio.h file before going to actual compilation.
 The next line int main() is the main function where the program execution begins.
 The next line /*...*/ will be ignored by the compiler and it has been put to add
additional comments in the program. So such lines are called comments in the
program.
 The next line printf(...) is another function available in C which causes the message
"Hello, World!" to be displayed on the screen.
 The next line return 0; terminates the main() function and returns the value 0.

Compile and Execute C Program

Let us see how to save the source code in a file, and how to compile and run it. Following
are the simple steps −
 Open a text editor and add the above-mentioned code.
 Save the file as hello.c
 Open a command prompt and go to the directory where you have saved the file.
 Type gcc hello.c and press enter to compile your code.
 If there are no errors in your code, the command prompt will take you to the next line
and would generate a.out executable file.
 Now, type a.out to execute your program.
 You will see the output "Hello World" printed on the screen.
$ gcc hello.c
$ ./a.out
Hello, World!

You might also like