Need help adding colour to the outputs of my C programs instead of the usual black and white screen.
I've read the setconsoleattribute thread and it's too advance for me...Is there any other way to do it or is that the only way?
Need help adding colour to the outputs of my C programs instead of the usual black and white screen.
I've read the setconsoleattribute thread and it's too advance for me...Is there any other way to do it or is that the only way?
you could output ansii escape codes to do coloring... but that's dos specific
Could u elaborate a little more?
How do I use that?
>>Need hlep with program output...fast!!
Don't ask for "fast" help. Read the forum netiquette rules.
You didn't mention what compiler/OS you are using, and colouring text is non-standard, so we can't really help you without the necessary info. (I guess you're on Windows console?)
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
you can do this from include <conio.h> file in code
the functions are setbkgroung(your color)
AbHHinaay
in dos u have 8 basic colors then there r 8 others but they r like this LIGHTGREEN LIGHTBLUE etc.
try this out if its in dos
#include <conio.h>
int textcolor();
textcolor=BLUE;/*always in capitals*/
then u say whatever u want to say in BLUE
> in dos u have 8 basic colors
conio.h only works with a DOS compiler IIRC, and if I'm not mistaken simply downloading conio.h will not help you any
The world is waiting. I must leave you now.
Thanx for all the help. And sorry about the "fast" comment. My apologies.
I'll look into the tips you all gave immediately. Thanx alot. =)
Erm....Could any of you please be a tiny bit more specific.
I'm really lost here about how to use the conio.h thing.
I've read the function synopsis that comes with my lccwin compiler but that doesn't help.
Could anyone please post a sample code? Spmething really simple showing me proper way to use this.
I'm kinda really new to C. Hehehe
Thanx again
something .... with colors
Code:#include <stdio.h> #include <conio.h> int main() { int textcolor(); textcolor(BLUE); printf("\t\1\tThis is written in BLUE\t\1\n\n"); textcolor(MAGENTA); printf("This is written in MAGENTA"); return 0; }
I'm using lccwin32 and a very old version of Turbo C.......
and I can't compile your program.
It gives an warning and an error:
1. something about mismatch declaration at tcconio.h 123
2. an Error about undefine reference to textcolour?
These are the problems I was stuck with before I ask for a sample program from u guys.....The sample posted above had the same problems as well.
?? Can anyone offer help?
Borland C (not Turbo C) uses textcolor(int), but it *should* work with TC as well.
btw, basic dos colors are 0-7 for the background and 0-15 for the text color. If you use the dos based compiler, you might also try looking up int 10h in a search engine. inline asm is a lot more powerful for dos based apps than fooling around with conio.hCode:#include <stdio.h> #include <conio.h> int main(void) { textcolor(1), cprintf("This should be blue text."); return 0; }
I haven't used a compiler in ages, so please be gentle as I try to reacclimate myself. :P
u say it guves an error well i also have that error but u cancompile and it works just fine so why wouldnt u run it once?
f9 f5 f5
cuz i also use lcc win32 so ...
Unfortunately, it was an Error not a warning. Won't run at all....I'm not that noob till I won't thought of that. The sample GanglyLamb gave me can't compile on either my lccwin32 nor my old Turbo C. Something about "undefined reference to _textcolor".
Dunno why though.
The sample code given by Ronin has the same problem when I try it with lccwin32 but it works on Turbo C!!! For some obscure reason, my lccwin32 doesn't compile either sample codes...kept giving me warnings about tcconio.h header file and an error like the one I've mentioned b4.
Any ideas? And thanx a bunch to ronin and ganglylamb for the effort and the codes. I've learnt alot.
BTW, I've checked the indexed help on the lccwin32 and it does mention the textcolor function, syntax SEEMS correct.....I'm not too sure.