Printf in different colours?

This is a discussion on Printf in different colours? within the C Programming forums, part of the General Programming Boards category; Running Windows Vista Using Cygwin Now everytime something is printed on to the screen it's always in white colour. How ...

  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
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,506
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    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
    Aia
    Aia is offline
    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,046
    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
    21,662
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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,682
    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, 08:48 PM
  2. making it portable.....?
    By ShadeS_07 in forum C Programming
    Replies: 11
    Last Post: 12-24-2008, 08:38 AM
  3. get keyboard and mouse events
    By ratte in forum Linux Programming
    Replies: 10
    Last Post: 11-17-2007, 04: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, 08:23 AM
  5. Drawing tables in C
    By stanoman in forum C Programming
    Replies: 5
    Last Post: 10-09-2003, 10:14 AM

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