changing the color of my text

This is a discussion on changing the color of my text within the C Programming forums, part of the General Programming Boards category; can anyone show me how to change the text color in a normal printf? i can't find a thing on ...

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    8

    changing the color of my text

    can anyone show me how to change the text color in a normal printf? i can't find a thing on the net and my compilers help file makes no sence. i just need the syntax and the header files i have to include. any help would be great because im a newb to this language lol. also im running a compiler called Watcom express c version 8 if that helps

  2. #2
    .........
    Join Date
    Nov 2002
    Posts
    303
    If your using windows type "color ?" without the " while in the console.
    It will show you a list of the available colors you can use.
    Then just use the color codes like this in a program.
    Code:
    system("color 71");
    This would give you a white background with blue text.

    There's other ways to do this but this is the easiest.

  3. #3
    Registered User
    Join Date
    Feb 2003
    Posts
    8
    when i compile the program says: bad command or file name and the text is the same color. im running windows 2k if thats an issue. just for added clarity, i want to print text to the screen like a hello world program just in differant colors.

  4. #4
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    Read the FAQ. It should be there. If not search its been covered many many many times.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  5. #5
    Registered User
    Join Date
    Feb 2003
    Posts
    8
    lol my luck eh! the FAQ put, text coloring on the to do list. guess ill just have to search this forum unless someone shows mercy

  6. #6
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    ok im bored ill show some mercy....

    HAMMER.... Add to FAQ if u like....

    This is windows specific for changing text colour in the console.

    First things first we need a handle to the console. This is obtained by calling GetStdHandle()
    Code:
    HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE);
    if (hCon == INVALID_HANDLE_VALUE) // cant find console window do something errorlike
    Next you need to call SetConsoleTextAttribute()....
    Code:
    SetConsoleTextAttribute(hCon,FOREGROUND_RED | BACKGROUND_BLUE | BACKGROUND_INTENSITY);
    // red text on light blue background
    The last param to SetConsoleTextAttribute controls the text and background colours. The possible values are...
    FOREGROUND_RED
    FOREGROUND_BLUE
    FOREGROUND_GREEN
    FOREGROUND_INTENSITY
    BACKGROUND_RED
    BACKGROUND_BLUE
    BACKGROUND_GREEN
    BACKGROUND_INTENSITY
    0 (black)
    You bitwise or (operator | ) together the values above in different combinations for different text effects. the intensity variants just lighten. blue becomes light blue. etc. The others should be self-explanatory.Play around. See what you can do.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  7. #7
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    forgot to mention those functions are available from <windows.h>
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  8. #8
    Registered User
    Join Date
    Feb 2003
    Posts
    8

    Talking

    thanks you made my day!

  9. #9
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    What if you want to change the text back to white?
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  10. #10
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    | all 4 foreground constants together for bright white. Leave intensity out for a dull white/lt gray
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  11. #11
    Registered User
    Join Date
    Oct 2006
    Posts
    3

    BUT

    Quote Originally Posted by Stoned_Coder
    | all 4 foreground constants together for bright white. Leave intensity out for a dull white/lt gray

    Hi, How I can return to Black and White

  12. #12
    Registered User
    Join Date
    Oct 2006
    Posts
    3
    Quote Originally Posted by DioxFx
    Hi, How I can return to Black and White

    Sorry, I'm dummy, the answer is up!, sorry, but... then I can't return to White?

  13. #13
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598
    Please don't crosspost. This is also on the game programming forum.

  14. #14
    Registered User
    Join Date
    Sep 2006
    Posts
    17
    oo..this is great...if ur using windows just tupe color 0A in the console and then run ur programs ...i dont know why ur bothered abuot the color so much

  15. #15
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,851
    Previous post before DioxFx graced us with is magnificence
    > 03-04-2003, 07:25 PM
    Don't bump threads
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 05-25-2005, 02:50 PM
  2. Changing text color
    By bluehead in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 08-17-2003, 06:08 PM
  3. Replies: 1
    Last Post: 07-13-2002, 06:45 PM
  4. Changing the Console text back to black
    By Unregistered in forum C++ Programming
    Replies: 11
    Last Post: 07-12-2002, 09:11 AM
  5. Ok, Structs, I need help I am not familiar with them
    By incognito in forum C++ Programming
    Replies: 7
    Last Post: 06-29-2002, 10:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21