Solved

colored printf

Posted on 2004-05-02
6
355 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 6

Accepted Solution

by:
MannSoft earned 125 total points
Comment Utility
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
Comment Utility
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
Comment Utility
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
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.

763 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

10 Experts available now in Live!

Get 1:1 Help Now