Colored Text in C

This is a discussion on Colored Text in C within the C Programming forums, part of the General Programming Boards category; Hello people I would like to know how to output colored text in c, im using borland c++ 5.02. A ...

  1. #1
    Registered User
    Join Date
    Feb 2004
    Posts
    1

    Colored Text in C

    Hello people

    I would like to know how to output colored text in c, im using borland c++ 5.02.
    A short code with text "hi" in color and with some background color would be great... but the idea is basically what i want.

    i have found some solutions but mostly for c++ and it doesn't help me.

    thank you all

  2. #2
    Registered User
    Join Date
    Jan 2004
    Posts
    7
    Hi!


    There are several ways. The most simple one is to include conio.h. Some of the functions defined there will do the trick.

    A better interface is available in the Ncurses library and its Win32 ports (eg: PDCurses). With Curses you can output text in any color, add background colors, basic text formatting / effects (ie: underline, bold, blink etc) and much more. Check it out!
    Last edited by Karl; 02-22-2004 at 07:53 AM.

  3. #3
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,157

    Re: Colored Text in C

    Originally posted by colorC
    Hello people

    I would like to know how to output colored text in c, im using borland c++ 5.02.
    A short code with text "hi" in color and with some background color would be great... but the idea is basically what i want.

    i have found some solutions but mostly for c++ and it doesn't help me.

    thank you all
    Look in your conio.h header file. If you see functions that look like color functions, that's them. My Turbo 1 and Borland 5.5 have them, so they should be in your version.
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  4. #4
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,659
    Here is a good tutorial.

    gg

  5. #5
    c99
    c99 is offline
    Registered User
    Join Date
    Feb 2004
    Posts
    79
    As far as I'm aware there are no functions in standard C
    that create different colored console text.
    Check to see if you have a graphics library.

    You may like to try ANSI escape sequences eg: <ESC>[2J;

    Try this link for starters. http://www.termsys.demon.co.uk/vtansi.htm

    Using ansi terminal control sequences may require that ansi.sys
    is loaded on MS systems, *nix systems should work too.

    Example: Print "Hi" to stdout.

    <ESC>[2J clears screen and homes cursor, 34;m colors text blue.

    Code:
    #include <stdio.h>
    
    int main()
    {
        printf("\0x0B[2J;34;m%s", "Hi");
    
        return 0;
    }
    Hope that helps.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to use FTP?
    By maxorator in forum C++ Programming
    Replies: 8
    Last Post: 11-04-2005, 02:17 PM
  2. Replies: 1
    Last Post: 07-13-2002, 05:45 PM
  3. how to cout colored text?
    By Guanhui in forum C++ Programming
    Replies: 1
    Last Post: 07-05-2002, 08:14 AM
  4. Ok, Structs, I need help I am not familiar with them
    By incognito in forum C++ Programming
    Replies: 7
    Last Post: 06-29-2002, 09:45 PM
  5. Colored Text
    By Yoshi in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 11-28-2001, 08:46 AM

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