Solved

colored printf

Posted on 2004-05-02
6
360 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

803 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