Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 109,558 C++ Programmers for FREE! Ask your question and get quick answers from experts. There are 1,379 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



color text in C programming

4 Pages V  1 2 3 > »   
Reply to this topicStart new topic

color text in C programming

paakfaat
post 4 Aug, 2008 - 08:30 PM
Post #1


New D.I.C Head

*
Joined: 4 Aug, 2008
Posts: 20

I 'm using DEV-C++ to write my c program. And also I want to change the text color in the program in windows console environment. From my knowledge, I know that we can change 15 colors by using
CODE
SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED);

However I need more colors. I heard that curses can do it. But in DEV-C++, there are not <curses.h> header file. And I don't really understand how to use it or if it can help me to use with more colorful text color. Also, I tried to download ncurses 5.6 and curses 1.23. However, I don't know if they are useful or not. And I don't know how to use them.
So, please help me to answer the question.
And I need a example program which can be compiled in DEV-C++. Also, I'm using windows but not unix or linux. And my knowledge is very limited, please give me more details about it. Thank you.
User is offlineProfile CardPM

Go to the top of the page


no2pencil
post 4 Aug, 2008 - 08:40 PM
Post #2


Wet D.I.C.

Group Icon
Joined: 10 May, 2007
Posts: 4,948



Thanked 27 times

Dream Kudos: 2325

Expert In: Goofing Off

My Contributions


Have you tried using escape characters? I believe these will give you 16 bit color, as well as bold, blinking, & underline effects.

cpp

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

int main(void) {
cout << "regular " << '\033' << '[' << "boldface" << endl;
}
User is online!Profile CardPM

Go to the top of the page

paakfaat
post 4 Aug, 2008 - 09:05 PM
Post #3


New D.I.C Head

*
Joined: 4 Aug, 2008
Posts: 20

But I'm using C language. I don't know how to use C++. Anyway, thanks for you suggestion.
User is offlineProfile CardPM

Go to the top of the page

no2pencil
post 4 Aug, 2008 - 09:08 PM
Post #4


Wet D.I.C.

Group Icon
Joined: 10 May, 2007
Posts: 4,948



Thanked 27 times

Dream Kudos: 2325

Expert In: Goofing Off

My Contributions


QUOTE(paakfaat @ 5 Aug, 2008 - 12:05 AM) *

But I'm using C language.


Oops, my bad. So you replace the cout with printf.

Maybe this will help you out just a bit more :

cpp

#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);
}
User is online!Profile CardPM

Go to the top of the page

paakfaat
post 4 Aug, 2008 - 09:19 PM
Post #5


New D.I.C Head

*
Joined: 4 Aug, 2008
Posts: 20

Thanks for your reply
I tried it in DEV-C++ and compiled it.
But the output is
[1;31;40mIn color
[0;37;40m
and something that the keyboard don't have.
The color still didn't change at all.
So what can I do?

This post has been edited by paakfaat: 4 Aug, 2008 - 09:23 PM
User is offlineProfile CardPM

Go to the top of the page

Whizzy
post 4 Aug, 2008 - 09:28 PM
Post #6


D.I.C Lover

*****
Joined: 11 Aug, 2007
Posts: 1,299



Thanked 4 times
My Contributions


I hate to steer anyone away from DIC, however since your question is compiler specific, have you tried to go to the forums on Bloodshed.com?
User is offlineProfile CardPM

Go to the top of the page

paakfaat
post 4 Aug, 2008 - 09:38 PM
Post #7


New D.I.C Head

*
Joined: 4 Aug, 2008
Posts: 20

Bloodshed.com? I didn't heard it before. Let's go and see. Thank you. But any guideline? Or I will check it out myself.
Also what is DIC? I guess it is another C compiler. Where can I download it


This post has been edited by paakfaat: 4 Aug, 2008 - 09:49 PM
User is offlineProfile CardPM

Go to the top of the page

gabehabe
post 5 Aug, 2008 - 02:33 AM
Post #8


T3H R0XX0R!

Group Icon
Joined: 6 Feb, 2008
Posts: 2,625



Thanked 51 times

Dream Kudos: 1550

Expert In: (X)HTML, CSS, Batch Scripting, C, C++

My Contributions


This is DIC! Dream In Code!

And Bloodshed are the makers of Dev-C++ you should see "Bloodshed Dev-C++" on the splash screen smile.gif
User is offlineProfile CardPM

Go to the top of the page

paakfaat
post 5 Aug, 2008 - 04:39 AM
Post #9


New D.I.C Head

*
Joined: 4 Aug, 2008
Posts: 20

Ok. thank you very much.
so is the differences between DIC and Dev C++ ?
So is DIC also a compiler?
Is DIC also a C porgramming language?
I would like to know where can I download it.

This post has been edited by paakfaat: 5 Aug, 2008 - 05:07 AM
User is offlineProfile CardPM

Go to the top of the page

Hyper_Eye
post 5 Aug, 2008 - 06:10 AM
Post #10


D.I.C Head

**
Joined: 13 Sep, 2007
Posts: 72



Thanked 3 times
My Contributions


QUOTE(paakfaat @ 5 Aug, 2008 - 06:39 AM) *

Ok. thank you very much.
so is the differences between DIC and Dev C++ ?
So is DIC also a compiler?
Is DIC also a C porgramming language?
I would like to know where can I download it.


DIC is this entire website. It is not a compiler. DIC is Dream In Code which is the website you are posting on here.
User is offlineProfile CardPM

Go to the top of the page

paakfaat
post 5 Aug, 2008 - 06:40 AM
Post #11


New D.I.C Head

*
Joined: 4 Aug, 2008
Posts: 20

ok, thanks.
But how can I write the text with more than 15 color. Since Whizzy said that the problem is compiler specific. I asked the probelm in the forums of Bloodshed.com but there are no reply. Therefore, any C compiler can work with more than 15 colors. Or any other method can help me to write text with more than 15 colors?

As no2pencil gives a suggestion. What compiler does he use? So that his program can be compiled successfully?

This post has been edited by paakfaat: 5 Aug, 2008 - 06:42 AM
User is offlineProfile CardPM

Go to the top of the page

Tom9729
post 5 Aug, 2008 - 07:28 AM
Post #12


Debian guru

Group Icon
Joined: 30 Dec, 2007
Posts: 1,404



Thanked 7 times

Dream Kudos: 325
My Contributions


Setting the text color is not AFAIK part of Standard C.

There are however a few results here.

Next time please use Google first. smile.gif
User is online!Profile CardPM

Go to the top of the page

4 Pages V  1 2 3 > » 
Reply to this topicStart new topic
Time is now: 9/7/08 11:17PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month