Sunday, 11 January 2015

How to change text color and text background in Turbo C/C++ without using graphics

<marquee>Text and background color in turbo C++/C</marquee>


Everyone wants to create a good looking and attractive..
Using graphics for small programs is very clumsy, time consuming and a bit hard task to do..
So is there any other way???
Yes!!! there is !!!
And today i will teach you how to change text color and text background in Turbo C/C++
without using any graphics...
Before that if you don't have Turbo C/C++, then download one from here for win xp/7/8/8.1

Header file required is conio.hWe are going to use two functions
1. textcolor() : for changing color of text
2. textbackground() : for changing the background
supported colors are
BLACK, WHITE, RED, BLUE, BROWN, YELLOW, PINK, CYAN etc
it is necessary to write them in capital....
use them as follows:
textcolor(RED) :To change text color to red
textcolor(RED+BLINK) : to add blink efffect
similarly
textbackground(WHITE) : to change background to white


sample code:

#include<conio.h>

int main(void)
{
   int i, j;

   clrscr();
   for (i=0; i<9; i++)
   {
       for (j=0; j<80; j++)
 cprintf("C");
       cprintf("\r\n");
       textcolor(i+1);
       textbackground(i);
   }

   return 0;
   getch();
}




Output:






No comments:

Post a Comment

[How to] Connect an android device [using MTP] on Linux [Ubuntu 14.04 LTS] 100% working

I recently moved to Linux[Ubuntu 14.04 ] from windows 8.1 because it hangs a lot on my lappy. Apart from the cool features of Ubuntu , one...