Colorful printf...

This is a discussion on Colorful printf... within the A Brief History of Cprogramming.com forums, part of the Community Boards category; So I have this function "void textcolor(int color)" where "color" can be replaced with the basic 16 colors upon input. ...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    11

    Colorful printf...

    So I have this function "void textcolor(int color)" where "color" can be replaced with the basic 16 colors upon input.
    Code:
    void highvideo();
    void textcolor(int color);
    I don't understand how to impliment this with "printf" though. Is there a text string output function that allows &color INSIDE of the string? Example:
    Code:
    // Where &R is the color red and &B is blue
    printf("This &Rwould &Bbe &Rcolorful...");
    Any ideas on how I can impliment this into a string output function?

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    use cprintf() to print with colours, I think that the syntax is the same as in printf().
    Code:
    #include <stdio.h>
    #include <conio.h>
    
    int main()
    {
       textcolor(BLUE);
       textbackground(RED);
       cprintf("Hello world!");
       getch();
    }
    Last edited by Magos; 04-26-2002 at 03:11 PM.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    11
    Would you be willing to post iostream.h for me?

    I'm using LCC-WIN32 ver. 3.3 but it seems mine is bad.

    I get a redefinition error for "_op_piostream_int" when I try to include the header in my code. I didn't redefine it in my code either, it simply comes up as being defined twice in the header.

    So if you know you have a working version for my compiler, I'd appreciate you post it here.

  4. #4
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    You don't need iostream.h for cprintf(), just stdio.h
    And even if I send you iostream.h you only have the header, not the libraries.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  5. #5
    Registered User
    Join Date
    Apr 2002
    Posts
    11
    I need iostream.h for CIN and COUT (not so much COUT as CIN though.)

    However, if you tell me a different function that does the similar as CIN, then that'd be cool as well.

    I wanted the header file because that's where the error is coming from. The library files may not be the problem.

    Now I ask kindly: Please post iostream.h, if you don't want to, then you have no obligation to post an excuse on this thread. Thank you.

  6. #6
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    If you want the C-equivalent to cin, use scanf();
    printf() and scanf() is C
    cout & cin is C++

    Anyway, here's the file:
    Attached Files Attached Files
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. making it portable.....?
    By ShadeS_07 in forum C Programming
    Replies: 11
    Last Post: 12-24-2008, 09:38 AM
  2. get keyboard and mouse events
    By ratte in forum Linux Programming
    Replies: 10
    Last Post: 11-17-2007, 05:42 PM
  3. segmentation fault upon reload
    By yabud in forum C Programming
    Replies: 8
    Last Post: 12-18-2006, 06:54 AM
  4. Simple C question: user input to repeat a loop
    By evernaut in forum C Programming
    Replies: 2
    Last Post: 11-18-2006, 09:23 AM
  5. Drawing tables in C
    By stanoman in forum C Programming
    Replies: 5
    Last Post: 10-09-2003, 11:14 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21