We will begin our code in C language, with including a header file, which called "stdio.h", it has many instructions, which we will use in our code. Please don't ask the question "why we include header files ?", because I'll explain it later.
These files will be included by the " include " instruction, then we we'll write the code between the two brackets of the main function:
main ().
NB: every instruction must end with semicolon (;)
Our first instruction is printf, it allows us to display messages on the screen, its prototype is:
printf("messages");
Here is the code displaying "Hello every body":
To run this code, press (ctrl +F9) at the some time or click Run command, from the main menu.
After running you see nothing in the screen. Really the message was displayed, but you couldn't see it, because of execution's speed, so we will include another file " conio.h ", this file has a function called " getch() ", it waits untill a key pressed in the keyboard, and if no key pressed the computer don't pass to the next instruction.
Try this code:
As you see now, the message was displayed, but the message is displayed twice, the first is causal of the first running of the program before using getch() function, and the second is for the second running.
Run it again and you will see three messages and so on, so to display the message once at each running we will use " clrscr() " function, it clears the screen. It is in "conio.h".
Here is the code:
Now we'll display many messages on the screen:
Oh! another problem: the three messages was displayed at the some line, one inside the other.
To resolve this problem and to display each one in a line, we must tell the computer to return to the line by including the character (" \n ") at the end of every message.
Look at this code:
I think its Ok.
" " " pour "\""
" ' " pour "\' "
" % " pour "\%"
"? " pour "\?"
To display a message in the middle of the screen , we must use " gotoxy " instruction, it is in "conio.h", fellowed by the row and line muero r=80/2=40 ; l=25/2=12.5=12 or 13.
Gotoxy (40,12) ; Printf("middle") ;
| color | code | color | code |
| Black | 0 | blue | 1 |
| green | 2 | Cyan | 3 |
| Red | 4 | Magenta | 5 |
| Brun | 6 | White | 7 |
| Gris | 8 | light Blue | 9 |
| light green | 10 | light Cyan | 11 |
| light Red | 12 | light Magenta | 13 |
| Yellow | 14 | light White | 15 |
Ther is another function for background colour, it is " textbackground(c) ".
c : is the colour's numero.
Exemple :