Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C
How can we colour the output that is to be displayed on the screen?
Posted 30-Dec-12 21:28pm
Comments
Sergey Alexandrovich Kryukov at 31-Dec-12 2:35am
   
It depends where and how you display the output.
—SA
aspnet_regiis -i at 31-Dec-12 3:58am
   
Use colors..
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

textcolor(9); /* any number between 0 to 15)*/
cprintf("Your text");
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

#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 [^]
  Permalink  
Comments
Member 9720070 at 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)

  Print Answers RSS
0 OriginalGriff 7,105
1 DamithSL 5,079
2 Maciej Los 4,866
3 Sergey Alexandrovich Kryukov 4,617
4 Kornfeld Eliyahu Peter 4,384


Advertise | Privacy | Mobile
Web01 | 2.8.141223.1 | Last Updated 31 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100