C Online Compiler
Example: ANSI Escape Codes Console Color Example in C
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// ANSI Escape Codes Console Color Example #include <stdio.h> // ANSI foreground color codes #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" // Reset to default attributes // ANSI background color codes #define ANSI_BG_RED "\x1b[41m" #define ANSI_BG_GREEN "\x1b[42m" #define ANSI_BG_YELLOW "\x1b[43m" #define ANSI_BG_BLUE "\x1b[44m" #define ANSI_BG_MAGENTA "\x1b[45m" #define ANSI_BG_CYAN "\x1b[46m" int main() { // Step 1: Print text in green printf(ANSI_COLOR_GREEN "This text is green.\n" ANSI_COLOR_RESET); // Step 2: Print text in red with a yellow background printf(ANSI_COLOR_RED ANSI_BG_YELLOW "This text is red with a yellow background.\n" ANSI_COLOR_RESET); // Step 3: Combine colors and styles (e.g., bold blue text) printf("\x1b[1;34m" "This is bold blue text.\n" ANSI_COLOR_RESET); // 1 = bold, 34 = blue foreground // Step 4: A warning message in yellow printf(ANSI_COLOR_YELLOW "WARNING: Something might be wrong!\n" ANSI_COLOR_RESET); // Step 5: An error message in red printf(ANSI_COLOR_RED "ERROR: Critical failure detected!\n" ANSI_COLOR_RESET); return 0; }
Output
Clear
ADVERTISEMENTS