Thread: Need hlep with program output...fast!!

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    8

    Need hlep with program output...fast!!

    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?

  2. #2
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,490
    you could output ansii escape codes to do coloring... but that's dos specific

  3. #3
    Registered User
    Join Date
    Oct 2002
    Posts
    8
    Could u elaborate a little more?

    How do I use that?

  4. #4
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    magic conio.h

  5. #5
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>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]

  6. #6
    Registered User planet_abhi's Avatar
    Join Date
    Oct 2002
    Posts
    92
    you can do this from include <conio.h> file in code
    the functions are setbkgroung(your color)
    AbHHinaay

  7. #7
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    Location
    between photons and phonons
    Posts
    1,110
    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

  8. #8
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    > 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.

  9. #9
    Registered User
    Join Date
    Oct 2002
    Posts
    8
    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. =)

  10. #10
    Registered User
    Join Date
    Oct 2002
    Posts
    8
    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

  11. #11
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    Location
    between photons and phonons
    Posts
    1,110
    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;
    		}

  12. #12
    Registered User
    Join Date
    Oct 2002
    Posts
    8

    Unhappy

    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?


  13. #13
    Casual Visitor
    Join Date
    Oct 2001
    Posts
    350
    Borland C (not Turbo C) uses textcolor(int), but it *should* work with TC as well.

    Code:
    #include <stdio.h>
    #include <conio.h>
    
    int main(void)
    {
       textcolor(1), cprintf("This should be blue text.");
       return 0;
    }
    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.h
    I haven't used a compiler in ages, so please be gentle as I try to reacclimate myself. :P

  14. #14
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    Location
    between photons and phonons
    Posts
    1,110
    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 ...

  15. #15
    Registered User
    Join Date
    Oct 2002
    Posts
    8
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Program Plan
    By Programmer_P in forum C++ Programming
    Replies: 0
    Last Post: 05-11-2009, 01:42 AM
  2. Client-server system with input from separate program
    By robot-ic in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-16-2009, 03:30 PM
  3. Redirecting program output straight to an edit control
    By bennyandthejets in forum C++ Programming
    Replies: 5
    Last Post: 07-05-2004, 08:25 AM
  4. Program Output
    By lavon in forum C Programming
    Replies: 1
    Last Post: 03-19-2002, 10:32 PM
  5. Program Output
    By lavon in forum C Programming
    Replies: 1
    Last Post: 03-19-2002, 10:30 PM