Lesson 9
( Decoration of a program )
Hi and welcome back on learn 4 free programming!
In this lesson i will show you how can you decorate your program. When you make a program you can see black screen and white text. If you don't want that to appear on screen using some functions you can change everything.
Function cprintf()
We will start off with the simplest function, and that's cprintf(). Function cprintf() is used to change the color of the text. In function cprintf() that "c" is means "color". But tying only cprintf() in C code isn't enough.
The reason why that isn't enough is simple. For example:
Let's say that someone tell you to bring him a t-shirt and on bed are 5 t-shirts. You wouldn't know which one to bring him.
That's the same thing here. C language has 16 colors ( picture 1 ) and if you don't tell him which one you want it will print on screen text by default color ( white - 1 ).
For defining the color of the text is used function textcolor(). This function is writing above function cprintf() because it wont recognize the color ( which one to put ). When you typed textcolor you need to put the value of color ( picture 1 ) or type the color you want.
In this lesson i will show you how can you decorate your program. When you make a program you can see black screen and white text. If you don't want that to appear on screen using some functions you can change everything.
Function cprintf()
We will start off with the simplest function, and that's cprintf(). Function cprintf() is used to change the color of the text. In function cprintf() that "c" is means "color". But tying only cprintf() in C code isn't enough.
The reason why that isn't enough is simple. For example:
Let's say that someone tell you to bring him a t-shirt and on bed are 5 t-shirts. You wouldn't know which one to bring him.
That's the same thing here. C language has 16 colors ( picture 1 ) and if you don't tell him which one you want it will print on screen text by default color ( white - 1 ).
| Picture 1: 1-16 colors in C |
For defining the color of the text is used function textcolor(). This function is writing above function cprintf() because it wont recognize the color ( which one to put ). When you typed textcolor you need to put the value of color ( picture 1 ) or type the color you want.
- example:
right: textcolor(4);
cprintf("Some text");
wrong: cprintf("Some text");
textcolor(4);
One more thing if you write this:
One more thing if you write this:
textcolor(4);
Function textbackground()
printf("Some text");
It looks like it's right but it isn't because you didn't put cprintf(). So be careful with this, okay?
Function textbackground()
Next awesome function we are going to use is textbackground() function. I'm assuming that you figured out for what is this function is used. If you thought that it's for changing background color you were right, it is.
Like function text color in order to work you must write it above cprintf function. If you type only printf it wont put background color on text. When you placed it above cprintf next thing you need to do is to choose which color ( Picture 1 ) you want and put it.
![]() |
| Text background color |
right: textbackground(4);
cprintf("Some text");
wrong: cprintf("Some text");
textbackground(4);
Function setbkcolor()
This function is used when you want to change background color of whole screen. Unlike functions textbackground and textcolor, you can put this function where ever you want. It's recommended to put it at the beginning of code.
![]() |
| background color of screen |
- example:
#include <stdio.h>
int main(){
int a,b,c;
setbkcolor(RED); //-------> It will change background color of screen to red
.
.
.
return 0;
}
Okay that's it for this lesson come back to learn more about C.
I will be posting more lessons about C programming, so follow me, comment if there is something you would change :) .
If something doesn't work or you need help just email me on: sashans89@gmail.com and i will help you.
See you next time, Bye.
See you next time, Bye.
Sasha


No comments:
Post a Comment