Colors in C?

This is a discussion on Colors in C? within the C Programming forums, part of the General Programming Boards category; Hello, I want introduce color to my programs and I have tried using this: textcolor(YELLOW); But my compiler thinks YELLOW ...

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    16

    Colors in C?

    Hello, I want introduce color to my programs and I have tried using this:

    textcolor(YELLOW);

    But my compiler thinks YELLOW is a variable and says: line 23: variable 'YELLOW' not found. Is it that I have a bad compiler? It is Miracle C.


    Also I would like to know how to make my program wait before executing the next line so that I can give the effect of movement.


    Thankyou!

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,551
    > Is it that I have a bad compiler? It is Miracle C.
    Yes, you have a terrible compiler.
    Most people looking for something for $0 pick dev-c++ (http://www.bloodshed.net/dev/devcpp.html)
    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.

  3. #3
    Registered User
    Join Date
    Mar 2006
    Posts
    16
    Yes but isnt that a C++ compiler?

  4. #4
    Mad OnionKnight's Avatar
    Join Date
    Jan 2005
    Location
    Umeň, Sweden
    Posts
    555
    C++ compilers are C compilers as well but the support for the C standards differ between them.
    The reason you compiler doesn't recognize YELLOW is because it hasn't been defined. It's an enum defiined in conio.h so include it if your compiler supports it. It probably gives you a warning about textcolor() not being declared either as it's also related to conio.

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,551
    > Yes but isnt that a C++ compiler?
    Only if you name your source files as prog.cpp
    Name them as prog.c, and it will compile it as C.
    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.

  6. #6
    Registered User
    Join Date
    Mar 2006
    Posts
    16
    I just checked in the header directory but it doesnt have conio. Also it didnt give me a warning, only the error I told you about before. I think I am definitely going to get a new compiler!

    What do you mean by
    but the support for the C standards differ between them
    ?

    Thanks

  7. #7
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,161
    Changing to a new compiler won't necessarily gove you colors either. Since colors are an added feature and not standard, many, if not most, compilers don't define them -- including Dev-C AFAIK.

    Borland 5.5 does include color. It is a free download. http://www.borland.com/downloads/download_cbuilder.html
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  8. #8
    Mad OnionKnight's Avatar
    Join Date
    Jan 2005
    Location
    Umeň, Sweden
    Posts
    555
    All compilers comes with the Windows API libraries or has it downloadable on their site somwhere so you can use the function SetConsoleAttribute() instead. It's a bit more complicated but not too hard for a beginner and it's also "portable" between other compilers for Windows.

  9. #9
    Registered User
    Join Date
    Mar 2006
    Posts
    16
    Ok, I have something called Microsoft Visual C++ 6.0 on a CD. Is that what I need?

  10. #10
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,475
    Microsoft Visual 6.0 is old too. It is a little more recent than that C compiler. I am not sure if it supports windows.h, the header that contains colors. It may work. In C, if any compiler supports windows.h header files, like MSVC++ and the more recent additiions of DevC++ like 4.992 do support it, you can download this for free from their website free of charge with all the include files for you to use. Like salem said, change the code from cpp to c when you begin. If you tryed to include a C++ library, like iostream, it would complain an error but would except stdio.h as it is C not C++. Go with Dev if you want to use colors, but you will have to learn the syntax to get it to work, just remember to include the windows.h header file in your program

    -- hope this helps

  11. #11
    Newbie Crilston's Avatar
    Join Date
    Jun 2005
    Location
    Montreal, Canada
    Posts
    8
    If you're on Windows, you can use this to set the console text color:
    Code:
    HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleTextAttribute(hOut, FOREGROUND_* | BACKGROUND_*);
    // So FOREGROUND_GREEN | FOREGROUND_INTENSITY | BACKGROUND_INTENSITY
    //means light green text on a grey background (as in HLTV).
    Don't forget to include windows.h though.

  12. #12
    Registered User
    Join Date
    Sep 2005
    Posts
    8
    You can use escape sequences to make your code more portable.

    http://www.termsys.demon.co.uk/vtansi.htm
    Last edited by radiohead; 03-19-2006 at 03:09 PM.

  13. #13
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,161
    Microsoft Visual 6.0 is fine. Nothing wrong with it. And since you already have it, it's obviously free.

    And ANSI isn't as protable as it used to be. Your system has to support it -- which most don't directly now-a-days. It has to be set up.
    Last edited by WaltP; 03-19-2006 at 04:23 PM.
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  14. #14
    Registered User Bajanine's Avatar
    Join Date
    Dec 2001
    Location
    The most peaks over 10,000 feet!
    Posts
    396
    Since Bloodshed is also free. I'd suggest downloading it and giving it a try. As Salem suggested just rename the file with a .c extension or you can force Bloodshed to use c as shown below.
    Attached Images Attached Images  
    Favorite Quote:

    >For that reason someone invented C++.
    BLASPHEMY! Begone from my C board, you foul lover of objects, before the gods of C cast you into the void as punishment for your weakness! There is no penance for saying such things in my presence. You are henceforth excommunicated. Never return to this house, filthy heretic!



  15. #15
    Registered User
    Join Date
    Mar 2006
    Posts
    16
    Ok thanks I am going to use visual C++ 6 but also, in my original post I asked:

    "I would like to know how to make my program wait before executing the next line so that I can give the effect of movement."

    I would be grateful for advice.

    Jon

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why I only get 8 colors out of ncurses?
    By Nazgulled in forum C Programming
    Replies: 3
    Last Post: 05-08-2007, 06:06 PM
  2. Relation between material colors and light colors.
    By indigo0086 in forum Game Programming
    Replies: 3
    Last Post: 04-18-2007, 03:20 PM
  3. colors in forefox and colors in IE
    By MisterSako in forum Tech Board
    Replies: 3
    Last Post: 05-15-2006, 01:59 PM
  4. colors?
    By planet_abhi in forum Game Programming
    Replies: 1
    Last Post: 09-10-2003, 05:37 PM
  5. Text Colors
    By GaPe in forum C Programming
    Replies: 1
    Last Post: 07-11-2002, 06:57 AM

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