Thread: Printf in different colours?

  1. #1
    Cogito Ergo Sum
    Join Date
    Mar 2007
    Location
    Sydney, Australia
    Posts
    463

    Printf in different colours?

    Running Windows Vista
    Using Cygwin

    Now everytime something is printed on to the screen it's always in white colour. How can I get different colours ?

    Thanks

  2. #2

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Using gcc under cygwin, you can use ANSI Escape sequences
    Eg.
    Code:
    #define ESC "\032"
    printf( ESC "[2J" ); /* clears screen */
    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.

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Actually, AFAIK, you can use ANSI escape sequences as long as ANSI.SYS is loaded into memory, Cygwin or no.

    If you want to use a lot of coloured text and screen clearing and other fancy stuff, consider a library like ncurses. (I believe it comes with Cygwin -- it did with mine at least.)
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  5. #5
    Beautiful to C Aia's Avatar
    Join Date
    Jun 2007
    Posts
    124
    No intention of hijacking this thread. However, since Cygwin has been mentioned, I have a quick question: Is Cygwin a way of not to have to use MinGW port of gcc in Windows?

  6. #6
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    That's correct. However, Cygwin is more restricting than MinGW, DLL-wise. Programs using MinGW's GCC (e.g. compiled with Dev-C++) don't require any special DLLs or anything that I know of, besides standard Windows ones. Programs compiled with Cygwin do: cygwin.dll and cygwin1.dll, I think.

    On the other hand, Cygwin is much more complete. It has bash. I mean, look at all of the packages! http://cygwin.com/packages/
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  7. #7
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    However, Cygwin is more restricting than MinGW, DLL-wise. Programs using MinGW's GCC (e.g. compiled with Dev-C++) don't require any special DLLs or anything that I know of, besides standard Windows ones. Programs compiled with Cygwin do: cygwin.dll and cygwin1.dll, I think.
    Yeah, I would phrase it more like: is MinGW a way not to use Cygwin?

    Of course, if you want to be able to run configure scripts and such with MinGW, you also need to use MSYS, and even then the support for GNU/Linux tools is far more minimal than Cygwin.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  8. #8
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    Here is one more tutorila Change color.

    ssharish

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. IF CONDITION plese help
    By birumut in forum C Programming
    Replies: 12
    Last Post: 03-06-2009, 09:48 PM
  2. making it portable.....?
    By ShadeS_07 in forum C Programming
    Replies: 11
    Last Post: 12-24-2008, 09:38 AM
  3. get keyboard and mouse events
    By ratte in forum Linux Programming
    Replies: 10
    Last Post: 11-17-2007, 05:42 PM
  4. Simple C question: user input to repeat a loop
    By evernaut in forum C Programming
    Replies: 2
    Last Post: 11-18-2006, 09:23 AM
  5. Drawing tables in C
    By stanoman in forum C Programming
    Replies: 5
    Last Post: 10-09-2003, 10:14 AM