OCJP

Colored Output in C (cprintf(), textcolor(), textbackground())

There are some color functions those can be used for colored output in c language. First you have to set colors using textcolor(COLOR) function.

You can also set background color using textbackground(COLOR) function. Then you have to use cprintf() for colored output.

Color Codes to be used are

128 Will be used to blink the output. You can use like 1+128 (Blue + Blinking) also.

Most important thing to remember is cprintf() does not translate \n or \r so if you want to use it then you must apply printf() for \n or \r separate.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
textcolor(RED);
textbackground(YELLOW);
cprintf("Hello");
printf("\n"); //printf for \n only
cprintf("GOOD MORNING");
textcolor(BLUE + 128);
printf("\n");
cprintf("Enjoy with Color");
getch();
}

Leave a Reply

Your email address will not be published. Required fields are marked *


× How can I help you?