Say i just do a simple printf statement

printf("i want this text to be different color > %s", thisbit);

i want whatever i print out at the %s (the string) to be different color.
Im sure it only something little that why i ask.

8 Years
Discussion Span
Last Post by Adak

Never mind find out.

For anyone else who was curious. Type one of these before the text you want to

\033[22;30m - black
\033[22;31m - red
\033[22;32m - green
\033[22;33m - brown
\033[22;34m - blue
\033[22;35m - magenta
\033[22;36m - cyan
\033[22;37m - gray
\033[01;30m - dark gray
\033[01;31m - light red
\033[01;32m - light green
\033[01;33m - yellow
\033[01;34m - light blue
\033[01;35m - light magenta
\033[01;36m - light cyan
\033[01;37m - white

e.g. for light blue

printf(" \033[01;34m Hello World");

Edited by phil750: n/a


The codes shown above this, require that your system has the ANSI.sys driver loaded. (shades of DOS!)

I don't have it on my WindowsXP, system, so it won't work for me.

If you're working or writing code for a Windows system, I strongly suggest you use the Windows API for this, instead.


Then your distro has a version of ansi.sys installed. This was heavily used in the early days of DOS. I used it also.

I'll have to see if I can install it into my WindowsXP system, although Windows does have it's own API for this. I believe it's called SetConsoleTextColor().

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.