How can I change the colour of my output program?
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?...
How can I change the colour of my output program?
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)
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
I forgot to mention the "textcolor" function. This function and the cprintf are in "conio.h" library.
Use:
Have phun.Code:# include <conio.h> int main() { textcolor(RED); cprintf("Hello!"); return 0; }
Current projects:
1) User Interface Development Kit (C++)
2) HTML SDK (C++)
3) Classes (C++)
4) INI Editor (Delphi)
lets say i want to write this is green
printf("this is green");
how do i do this
Here's a fun little thing I wrote in response to a similar question on the C++ boards, modified for C of course
-PreludeCode:#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; }
My best code is written with the delete key.