1. Welcome to the world of Computer Programming Language learning!
Here I’ll present a short description about opening a project and use it
multiple times and running your first program.
At first install code-blocks and open it
Now click “open a new project”
2. Now give a title and select a save directory in your expected place
4. Build the code using the wheel key shown
The Run the code
5. Press any key
Now close code blocks
Now go the folder
Now delete the main.cpp and main.o files(the directories are shown in the pic)
6. Now open code blocks
From menu go the
File>new>file
Select c/c++ source file
Then select C
7. Give a title and save it to the test(the project folder that you created earlier)
8. Now write the sample code
Now build it and Run
Now you have successfully run a C code.
Congratulations……..
9. Some points about the sample code.
Consider the following portion as a skeleton of c code. You are not supposed
to understand everything in todays class, since many aspects are yet to be
touched, after four/five classes you’ll understand the different parts of this
code.
#include<stdio.h>
int main()
{
return 0;
}
Here “#” overrides the administrative privilege
Then include tells the compiler to add some header file
“<stdio.h>” is standard input/output header file. Here some common codes
regarding showing something on screen or taking input, are stored so that we
needn’t write the same code every time, but use a shortcut key instead.
“int main()” is a function declaration where int is the return type of the result
of the function, main is the function name and within parenthesis, we usually
give function arguments.
In a single c code there must be one “main”function which is the brain of the
code and maintain other functions when used (be patient! We’ll come to that
later).
Since we used an int(key word for integer), we wrote return 0;
A “;” ends any statement.
Curly brace”{ }” bind a code segment.
Here we’ve used a library(defined) function “printf”.
Printf can show anything that you write within double quote “printf(“ write
here ”);”.
If you write two printf within the code, like
10. printf(“first line”);
printf(“second line”);
when u run these then you’ll see that there are no space between those two
lines. If u want to give something like “enter”, then use “n” that gives an
enter explicitly.
Like
printf(“first linen”);
printf(“second line”);
or try this
printf(“first linen”);
printf(“nsecond line”);
then this
printf(“first linenn”);
printf(“nnsecond line”);
you can give tabs by”t”
printf(“first t line”);
printf(“second line”);
Now u can show anything to the user through the command prompt screen,
try doing these things at home until the next class.
In the next class we’ll learn how to take information from user and manioulte
them and then give user a response.