Thread: change color text?

  1. #1
    Registered User
    Join Date
    Mar 2005
    Posts
    18

    Question change color text?

    hi people!
    my question is how change the color of text that i send to stdout(display screen) in my linux.
    What is the function and in that header file is on?

    Tnks!
    /**************Um abraço*************/

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Well the short answer is to use ANSI escape sequences
    http://www.delmar.edu/Courses/CIS415L/ANSIsys.htm

    Example
    Code:
    printf( "\033[31mThis is Red\n" );
    A better way is to use the ncurses library since that is ported to a number of different platforms.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User xxxrugby's Avatar
    Join Date
    Jan 2005
    Posts
    178
    Is this ncurses library upper link or!

    I tried this what you wrote on Windows. And doesent work. How can I make that in Windows. If there is some way without using windows.h or with windows.h but some easy way?
    Somethink like
    Code:
    printf(RED -> "like this");
    Sorry for spelling errors, not English!
    xxxrugby: "All Human Race Will Die From My Hand!"
    xxxrugby: "We are all philosophers, when question is about politics!"

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You use either compiler specific library functions, or you use ANSI secape sequences as stated, and hope they're displayed by your enviornment.

    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > I tried this what you wrote on Windows. And doesent work.
    Well done - you noticed that the OP said Linux.

    Yes, there is a win32 version of ncurses (I'm sure google will find it).

    Also, check out Adrianxw's website for win32 console tutorial.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. type casting?
    By greatonesv in forum C Programming
    Replies: 12
    Last Post: 10-22-2008, 08:21 PM
  2. c++builder6 change form names problem
    By Leite33 in forum C++ Programming
    Replies: 2
    Last Post: 06-09-2008, 08:20 AM
  3. Change Value in an array
    By beginner999 in forum C Programming
    Replies: 3
    Last Post: 01-18-2003, 07:16 AM
  4. Replies: 2
    Last Post: 11-08-2002, 03:22 AM
  5. Replies: 2
    Last Post: 09-04-2001, 02:12 PM