colored printf

Hi All,

Very stupid question,

I want to print to the console in diffrent colors (red blue green) and so on ...

like we used to do in the old Assembly,

Thanks,

LVL 5
phyderousAsked:
Who is Participating?
 
MannSoftCommented:
Depends on the target platform.  If it's a Win32 console application, look up SetConsoleTextAttribute() on MSDN.  You could also see if your compiler has the conio.h include file.  Some do, some don't (it was originally Borland's, so it's not standard and not everyone has decided to make their own version).

Of course if it's a DOS target, you could still be using the goold old assembly method, so I'll assume the above is what you needed.
0
 
grg99Commented:
You can do it if your console support the ANSI.SYS escape codes, as does Windows all the way thru NT.

0
 
AxterCommented:
You can use CURSES.H

And for Linux and UNIX you can use ncurses.h

See following links:
dickey.his.com/ncurses/ncurses-intro.html
www.tldp.org/HOWTO/NCURSES-Programming-HOWTO
ftp://rpmfind.net/linux/redhat/8.0/en/os/i386/RedHat/RPMS/ncurses-5.2-28.i386.rpm

When you compile your code, make sure you include the cures library.
Example:

gcc test.c -o -lcurses
gcc test.c -o -lncurses
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
phyderousAuthor Commented:
I am using windows,

I tried the ansi.sys escape code with no luck ...

grg99 can you show me some sample of this

Thankx
0
 
grg99Commented:
What version of Windows?     It's possible XP has tailed off support.

Here's a good link with header files and examples:

http://mathbits.com/MathBits/CompSci/Graphics/ansi.htm

0
 
rstaveleyCommented:
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.