Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Color text/background in console mode C 1

Status
Not open for further replies.

Josiefuz

Programmer
Oct 26, 2002
7
US
Hi, I'm taking a C (not C++) class in school and would like to spruce up a program I'm writing. It's a console (DOS) application and uses standard printf to print to the screen.

How do I change the color of the text or background to add some sizzle?

Note: I'm using MiracleC compiler (which is very primitive and doesn't have many includes)

Thanks!

-Fuz
 
Try something like...
[tt]
printf("\033[33;44m");
[/tt]
This will set the screen to yellow characters on a blue background. These are ASNI escape sequences. They start with an ESCape and a "[", then a code to control something.

See for more info.

Hope this helps.
 
Thanks for the reply Sam.

When I run this I get: "" rather than color changes though. Do I have to run ansi.sys to use this?

-Fuz

 
Yeah, as the page at the URL I gave says...

Before issuing any ANSI escape sequences, you must load the special device driver ANSI.SYS. To do this, create or edit your CONFIG.SYS file in the root directory of the MSDOS Boot drive (C:\) and add the following command to it.

DEVICE=C:\DOS\ANSI.SYS or
DEVICE=C:\WINDOWS\COMMAND\ANSI.SYS

When you restart MSDOS, the ANSI.SYS driver extended screen and keyboard control driver will be installed.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top