When I run this locally, I also observe some odd behavior.
Using:
#define COL_RESET "\0x1b[39;49m"
Conclusion:

Changing my #define to use octal rather than hexadecimal produces a different (expected) result.
Using:
#define COL_RESET "\033[39;49m"
Conclusion:

You can also see the creation of a macro to use printf with colors.
#include <stdio.h> #define COL_RESET "\033[39;49m" #define COL_BG_RED "\033[41m" #define COL_BG_NORMAL "\033[49m" #define COLOR_NORMAL "\033[m" #define COLOR_RESET "\033[0m" #define COLOR_BLACK "\033[30m" #define COLOR_RED "\033[31m" #define COLOR_GREEN "\033[32m" #define COLOR_YELLOW "\033[33m" #define COLOR_BLUE "\033[34m" #define COLOR_MAGENTA "\033[35m" #define COLOR_CYAN "\033[36m" #define COLOR_WHITE "\033[37m" #define COLOR_PRINTF(colorCode,fmt,...) printf("%s" fmt "%s", colorCode, __VA_ARGS__, COL_RESET) char *str = "the quick brown fox jumped over the lazy dog"; int main(int argc, char *argv[]) { int i = 1; while (i) { COLOR_PRINTF(COLOR_GREEN, "%s\n", str); COLOR_PRINTF(COL_BG_RED, "%s\n", str); i--; } return 0; }
source share