Font Color

This is a discussion on Font Color within the C Programming forums, part of the General Programming Boards category; Is there a way to color the text displayed on screen for a program in C...

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    41

    Question Font Color

    Is there a way to color the text displayed on screen for a program in C

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    70
    Like in a windows or dos

  3. #3
    Registered User
    Join Date
    Mar 2002
    Posts
    95
    if your doing it in a borland compiler you can use the command
    cprintf (contained in the conio.h file) and use something like:
    textcolor(7);
    and
    textbackground(0);
    to change the color of the writing to that specified in the brackets, but this is a non standard way so all depends on what you need it for, etc.

  4. #4
    Registered User
    Join Date
    May 2002
    Posts
    41
    It's for a DOS program. I'm using Bloodshed Dev-C++ compiler. Can you give me an example using the textcolor(7) and textbacground(0) please if you can.

    Thanks

  5. #5
    Registered User
    Join Date
    Mar 2002
    Posts
    95
    i dont understand, it is simply those commands so if you wanted the text to be red you'd do:

    [code]
    #include <conio.h>

    int main()
    {
    textcolor(3);
    cprintf("\nTHIS TEXT IS RED\n");
    textcolor(18);
    cprintf("\nI THINK THIS IS FLASHING RED\n");
    }

    just have a play with it, hopefully its what your after, this command should also be in the help within borland to find out the exact numbers for each color.

  6. #6
    Registered User
    Join Date
    May 2002
    Posts
    41
    I tryed to compile in Dev-C++ and Miracle C but in Dev-C++ I get
    "[Linker error] undefined reference to `textcolor'"
    and some other error in Miracle C. What's going on?
    Shouldent NULL be, 78, 85, 76, 76, or just 0 or, 4E, 55, 4C, 4C

  7. #7
    Registered User
    Join Date
    May 2002
    Posts
    41
    I have the right header in too. And my compiler supports conio.h
    Shouldent NULL be, 78, 85, 76, 76, or just 0 or, 4E, 55, 4C, 4C

  8. #8
    Registered User
    Join Date
    Mar 2002
    Posts
    95
    I'm guessing your compiler or version of conio.h doesnt support textcolor, if you have a look or do a file search for anything that contains the words color or colour, then maybe you might find something in the .h files.

  9. #9
    Registered User
    Join Date
    May 2002
    Posts
    41
    here's whats in my conio.h when I opened it. It has stuff about color but I dont know what some of it means.


    #ifndef _CONIO_H_
    #define _CONIO_H_


    #include <stdio.h>

    #ifdef __cplusplus
    extern "C" {
    #endif

    #define BLINK 0

    typedef enum
    {
    BLACK,
    BLUE,
    GREEN,
    CYAN,
    RED,
    MAGENTA,
    BROWN,
    LIGHTGRAY,
    DARKGRAY,
    LIGHTBLUE,
    LIGHTGREEN,
    LIGHTCYAN,
    LIGHTRED,
    LIGHTMAGENTA,
    YELLOW,
    WHITE
    } COLORS;


    #define cgets _cgets
    #define cprintf _cprintf
    #define cputs _cputs
    #define cscanf _cscanf
    #define ScreenClear clrscr

    /* blinkvideo */

    void clreol (void);
    void clrscr (void);

    int _conio_gettext (int left, int top, int right, int bottom,
    char *str);
    /* _conio_kbhit */

    void delline (void);

    /* gettextinfo */
    void gotoxy(int x, int y);
    /*
    highvideo
    insline
    intensevideo
    lowvideo
    movetext
    normvideo
    */

    void puttext (int left, int top, int right, int bottom, char *str);

    // Screen Variables

    /* ScreenCols
    ScreenGetChar
    ScreenGetCursor
    ScreenMode
    ScreenPutChar
    ScreenPutString
    ScreenRetrieve
    ScreenRows
    ScreenSetCursor
    ScreenUpdate
    ScreenUpdateLine
    ScreenVisualBell
    _set_screen_lines */

    void _setcursortype (int type);

    void textattr (int _attr);

    void textbackground (int color);

    void textcolor (int color);

    /* textmode */

    int wherex (void);

    int wherey (void);

    /* window */



    /* The code below was part of Mingw's conio.h */
    /*
    * conio.h
    *
    * Low level console I/O functions. Pretty please try to use the ANSI
    * standard ones if you are writing new code.
    *
    * This file is part of the Mingw32 package.
    *
    * Contributors:
    * Created by Colin Peters <colin@bird.fu.is.saga-u.ac.jp>
    *
    * THIS SOFTWARE IS NOT COPYRIGHTED
    *
    * This source code is offered for use in the public domain. You may
    * use, modify or distribute it freely.
    *
    * This code is distributed in the hope that it will be useful but
    * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
    * DISCLAMED. This includes but is not limited to warranties of
    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    *
    * $Revision: 1.4 $
    * $Author: hongli $
    * $Date: 2002/04/26 19:31:25 $
    *
    */

    char* _cgets (char*);
    int _cprintf (const char*, ...);
    int _cputs (const char*);
    int _cscanf (char*, ...);

    int _getch (void);
    int _getche (void);
    int _kbhit (void);
    int _putch (int);
    int _ungetch (int);


    int getch (void);
    int getche (void);
    int kbhit (void);
    int putch (int);
    int ungetch (int);


    #ifdef __cplusplus
    }
    #endif

    #endif /* _CONIO_H_ */
    Shouldent NULL be, 78, 85, 76, 76, or just 0 or, 4E, 55, 4C, 4C

  10. #10
    Registered User
    Join Date
    Mar 2002
    Posts
    95
    can u paste an example of your code.

  11. #11
    Registered User
    Join Date
    May 2002
    Posts
    41
    I was trying it the same way you where doing it. This is what i was trying to compile.

    #include <conio.h>
    #include <stdio.h>

    int main()
    {
    textcolor(3);
    cprintf("\nTHIS TEXT IS RED\n");
    textcolor(18);
    cprintf("\nI THINK THIS IS FLASHING RED\n");
    }
    Shouldent NULL be, 78, 85, 76, 76, or just 0 or, 4E, 55, 4C, 4C

  12. #12
    Registered User
    Join Date
    Mar 2002
    Posts
    95
    hmm not sure works fine for me, umm try to make sure that the directory to your include is set in your c:\autoexec.bat file, if its not then add it in, something like this at the end will do it

    set path=%path%;c:\progra~1\tc\include

    that way it'll no where to find conio.h, i'm guessing thats not the problem and if it isnt then i dont know whats wrong.

  13. #13
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669
    If you are programming a win32 console program then those function will not work. You should use the WINAPI functions.
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  14. #14
    Registered User
    Join Date
    May 2002
    Posts
    41
    Im programing it in DOS window.
    Shouldent NULL be, 78, 85, 76, 76, or just 0 or, 4E, 55, 4C, 4C

  15. #15
    Registered User red_baron's Avatar
    Join Date
    May 2002
    Posts
    274
    heh i use same comiler as you here is something i made to determine colours, it should be helpful.
    Attached Files Attached Files
    ¿Red Baron?

    "Imagination is more important than knowledge"
    -Albert Einstein (1879-1955)

    Check out my games!

    [code] /* dont forget code tags! */ [/code]

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

Similar Threads

  1. Critique my lighting model.
    By psychopath in forum Game Programming
    Replies: 4
    Last Post: 08-12-2006, 07:23 PM
  2. problem with my font manager
    By hannibar in forum C Programming
    Replies: 1
    Last Post: 03-07-2006, 08:03 AM
  3. char copy
    By variable in forum C Programming
    Replies: 8
    Last Post: 02-06-2005, 10:18 PM
  4. RichEdit Font Color
    By Unregistered in forum Windows Programming
    Replies: 2
    Last Post: 11-01-2003, 04:07 PM
  5. Just one Question?
    By Irish-Slasher in forum C++ Programming
    Replies: 6
    Last Post: 02-12-2002, 10:19 AM

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