top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to set font color for stdout and stderr?

+3 votes
458 views
How to set font color for stdout and stderr?
posted Feb 26, 2015 by Chirag Gangdev

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button
cant understand what is the requirement, can you explain the detail about the query.
How to print something on screen/stdout in different different color?

1 Answer

+1 vote
 
Best answer

You dont have a mechanism for stderr however for stdout you can use ANSI color code. Following is the sample code (will work only in Linux/Unix environment)

#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 () {
  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");
}

Use the following Wiki for more information on color codes
http://en.wikipedia.org/wiki/ANSI_escape_code#Colors

answer Feb 26, 2015 by Salil Agrawal
Thanks Sir..
Similar Questions
+2 votes
+1 vote

I am a newbie and using fedora machine, please help with point by point C programming setup.

+3 votes

A list contains a set of numbers, one number presents once and other numbers present even no. of times. Find out the number that occurs once in the list.

...