Results 1 to 6 of 6

Thread: C programming Coloring text

  1. #1
    Join Date
    Sep 2005
    Posts
    82

    C programming Coloring text

    For my c programming I use DEV-C++ to write and in the windows xonsole environment I need to change the text color in the program. As what I know that we can change 15 colors by using this code

    Code:
    SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED);
    But what I need is more colors & maybe curses can do it if I am not wrong. But there are not curses header file in DEV-C++ and I cannot understand how to use it or if it can be used with more colorful text color? I also downloaded ncurses 5.6 & curses 1.23 but dont know if it can be useful or not & how to use them is another thing? Also is there any example program that can be compiled in DEV. Also I am using windows platporm & not linux. So, please help me get all the info that i need. Thanks

  2. #2
    Join Date
    Dec 2007
    Posts
    1,599
    I think that you can use escape characters whihc will give you 16 bit color & many other effects.

    Code:
    #include <stdio.h>
    #include<iostream.h>
    #include<conio.h>
    
    int main(void) {
      cout << "regular " << '\033' << '[' << "boldface" << endl;
    }

  3. #3
    Join Date
    Sep 2005
    Posts
    82
    But I'm using C language. I don't know how to use C++. Anyway, thanks for you suggestion.

    Thanks for your comments but I am not using C++. I am using C language. Any other method? Thanks again

  4. #4
    Join Date
    Dec 2007
    Posts
    1,599
    Oops, my bad. So you replace the cout with printf.

    Maybe this will help you out just a bit more :


    Sorry, I didnt notice that you are using C language & you also replaced the cout with printf it seems. Hope this helps you out more.

    Code:
    #include <stdio.h>
    
    #define RESET           0
    #define BRIGHT          1
    #define DIM             2
    #define UNDERLINE       3
    #define BLINK           4
    #define REVERSE         7
    #define HIDDEN          8
    
    #define BLACK           0
    #define RED             1
    #define GREEN           2
    #define YELLOW          3
    #define BLUE            4
    #define MAGENTA         5
    #define CYAN            6
    #define WHITE           7
    
    void textcolor(int attr, int fg, int bg);
    int main() {
            textcolor(BRIGHT, RED, BLACK);
            printf("In color\n");
            textcolor(RESET, WHITE, BLACK);
            return 0;
    }
    
    void textcolor(int attr, int fg, int bg) {
            char command[13];
    
            /* Command is the control command to the terminal */
            sprintf(command, "%c[%d;%d;%dm", 0x1B, attr, fg + 30, bg + 40);
            printf("%s", command);
    }

  5. #5
    Join Date
    Sep 2005
    Posts
    82
    Thanks, I compiled it in in DEV-C++ but output is somewhat incorrect & the color didnt change as well. Is there something else that is needed?

  6. #6
    Join Date
    Dec 2007
    Posts
    1,736
    Try going to Bloodshed.com for all your questions. They are the makers of Dev-C++ Language.

Similar Threads

  1. Replies: 2
    Last Post: 04-01-2012, 06:54 PM
  2. Replies: 5
    Last Post: 28-02-2011, 08:23 PM
  3. BlackBerry Torch TEXT message icon not showing text messages
    By rOSAMOND in forum Portable Devices
    Replies: 8
    Last Post: 17-10-2010, 01:04 AM
  4. Socket programming: Is any new Programming Language?
    By Kushan in forum Software Development
    Replies: 3
    Last Post: 14-11-2009, 11:13 AM
  5. Replies: 3
    Last Post: 13-12-2008, 01:49 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,213,461.18616 seconds with 17 queries