output coloured text on screen

This is a discussion on output coloured text on screen within the C Programming forums, part of the General Programming Boards category; How can I change the colour of my output program?...

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    18

    output coloured text on screen

    How can I change the colour of my output program?

  2. #2
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669

    Thumbs up

    If your writing in DOS or WINDOWS enviroment than I'm recommending you a "cprintf" function.
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  3. #3
    Registered User
    Join Date
    Mar 2002
    Posts
    18
    Can I get different colours to go with different text, i.e. the cprintf statement makes sense, but how can I get different colours

    I am using windows

  4. #4
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669

    Thumbs up

    I forgot to mention the "textcolor" function. This function and the cprintf are in "conio.h" library.

    Use:

    Code:
    # include <conio.h>
    
    int main()
    {
    textcolor(RED);
    cprintf("Hello!");
    return 0;
    }
    Have phun.
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  5. #5
    Registered User
    Join Date
    Mar 2002
    Posts
    18
    lets say i want to write this is green

    printf("this is green");

    how do i do this

  6. #6
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Here's a fun little thing I wrote in response to a similar question on the C++ boards, modified for C of course
    Code:
    #include <stdio.h>
    #include <windows.h>
    #define HOT   FOREGROUND_INTENSITY
    #define RED   FOREGROUND_RED
    #define GREEN FOREGROUND_GREEN
    #define BLUE  FOREGROUND_BLUE
    
    int main ( void )
    {
      HANDLE h;
      h = GetStdHandle ( STD_OUTPUT_HANDLE ); 
      SetConsoleTextAttribute ( h, RED | GREEN ); 
      printf ( "My " );
      SetConsoleTextAttribute ( h, RED );
      printf ( "next " );
      SetConsoleTextAttribute ( h, GREEN );
      printf ( "rant " );
      SetConsoleTextAttribute ( h, HOT | BLUE );
      printf ( "will " );
      SetConsoleTextAttribute ( h, HOT | RED );
      printf ( "be " );
      SetConsoleTextAttribute ( h, HOT | GREEN );
      printf ( "in a " );
      SetConsoleTextAttribute ( h, HOT | BLUE | RED );
      printf ( "technicolor " );
      SetConsoleTextAttribute ( h, BLUE | GREEN );
      printf ( "rainbow :D\n" );
      SetConsoleTextAttribute ( h, GREEN | BLUE | RED );
      return 0;
    }
    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. output text to hyperterminal
    By baseball07 in forum Networking/Device Communication
    Replies: 3
    Last Post: 04-25-2007, 09:49 PM
  2. A bunch of Linker Errors...
    By Junior89 in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2006, 01:59 PM
  3. Base converter libary
    By cdonlan in forum C++ Programming
    Replies: 22
    Last Post: 05-15-2005, 01:11 AM
  4. char copy
    By variable in forum C Programming
    Replies: 8
    Last Post: 02-06-2005, 09:18 PM
  5. dos output screen
    By niroopan in forum C++ Programming
    Replies: 1
    Last Post: 09-15-2002, 09:03 AM

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