Solved

colored printf

Posted on 2004-05-02
6
364 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

739 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