Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 08-08-2008
Member
 
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
Reply With Quote
  #2  
Old 08-08-2008
Member
 
Join Date: Dec 2007
Posts: 1,592
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;
}
Reply With Quote
  #3  
Old 08-08-2008
Member
 
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
Reply With Quote
  #4  
Old 08-08-2008
Member
 
Join Date: Dec 2007
Posts: 1,592
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);
}
Reply With Quote
  #5  
Old 08-08-2008
Member
 
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?
Reply With Quote
  #6  
Old 08-08-2008
Member
 
Join Date: Dec 2007
Posts: 1,728
Try going to Bloodshed.com for all your questions. They are the makers of Dev-C++ Language.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "C programming Coloring text"
Thread Thread Starter Forum Replies Last Post
How to restore cell gridlines lost after coloring the cell in Excel? Chitti's Windows Software 2 04-01-2012 06:54 PM
TEXT message icon not showing text messages in BlackBerry curve 8520 Tabita Portable Devices 5 28-02-2011 08:23 PM
BlackBerry Torch TEXT message icon not showing text messages rOSAMOND Portable Devices 8 17-10-2010 01:04 AM
Socket programming: Is any new Programming Language? Kushan Software Development 3 14-11-2009 11:13 AM
JetBrains Introduces a New Programming Paradigm With its Meta Programming System JoeFrat Software Development 3 13-12-2008 01:49 PM


All times are GMT +5.5. The time now is 01:23 PM.