Click here to Skip to main content
15,867,330 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
How can we colour the output that is to be displayed on the screen?
Posted
Comments
Sergey Alexandrovich Kryukov 31-Dec-12 2:35am    
It depends where and how you display the output.
—SA
bbirajdar 31-Dec-12 3:58am    
Use colors..

C++
textcolor(9); /* any number between 0 to 15)*/
cprintf("Your text");
 
Share this answer
 
v2
C++
#include <stdio.h>

#define ANSI_COLOR_RED     "\x1b[31m"
#define ANSI_COLOR_GREEN   "\x1b[32m"
#define ANSI_COLOR_YELLOW  "\x1b[33m"
#define ANSI_COLOR_BLUE    "\x1b[34m"
#define ANSI_COLOR_MAGENTA "\x1b[35m"
#define ANSI_COLOR_CYAN    "\x1b[36m"
#define ANSI_COLOR_RESET   "\x1b[0m"

int main (int argc, char const *argv[]) {

  printf(ANSI_COLOR_RED     "This text is RED!"     ANSI_COLOR_RESET "\n");
  printf(ANSI_COLOR_GREEN   "This text is GREEN!"   ANSI_COLOR_RESET "\n");
  printf(ANSI_COLOR_YELLOW  "This text is YELLOW!"  ANSI_COLOR_RESET "\n");
  printf(ANSI_COLOR_BLUE    "This text is BLUE!"    ANSI_COLOR_RESET "\n");
  printf(ANSI_COLOR_MAGENTA "This text is MAGENTA!" ANSI_COLOR_RESET "\n");
  printf(ANSI_COLOR_CYAN    "This text is CYAN!"    ANSI_COLOR_RESET "\n");

  return 0;
}


more info on color code in ANSI escape code[^]

or have a tutorial Output Colorful Text using C Program [^]
 
Share this answer
 
Comments
Member 9720070 17-Jan-13 16:43pm    
Which are the header files required for cprintf and textcolor?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900