Solved

colored printf

Posted on 2004-05-02
6
359 Views
Last Modified: 2008-03-03
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,

0
Comment
Question by:phyderous
6 Comments
 
LVL 22

Expert Comment

by:grg99
ID: 10973452
You can do it if your console support the ANSI.SYS escape codes, as does Windows all the way thru NT.

0
 
LVL 30

Expert Comment

by:Axter
ID: 10975811
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
 
LVL 5

Author Comment

by:phyderous
ID: 10980270
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 6

Accepted Solution

by:
MannSoft earned 125 total points
ID: 10981109
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
 
LVL 22

Expert Comment

by:grg99
ID: 10981640
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
 
LVL 17

Expert Comment

by:rstaveley
ID: 10985991
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now