-1

My code is showing as follow:

#include <stdio.h>
void red () {
  printf("\033[1;31m");
}
void yellow (){
  printf("\033[1;33m");
}
void reset () {
  printf("\033[0m");
}
int main () {
  red();
  printf("Hello ");
  yellow();
  printf("world\n");
  reset();
  return 0;
}

When I run using Dev C++ as IDE, the output display somehow is not showing the right color/ Instead, it was showing as a bunch of regular text. How can I fix this in Dev C++?

enter image description here

  • I recommend you to use Windows API function `SetConsoleTextAttribute()` to set console text color in Windows. – Yuchen Ren Jun 01 '22 at 00:15
  • 3
    The terminal you are using clearly does not support the escape codes you are trying to use. – Remy Lebeau Jun 01 '22 at 00:15
  • for the old conhost terminal you may need to enable ANSI sequence support manually [Windows console with ANSI colors handling](https://superuser.com/a/1300251/241386), [How to make win32 console recognize ANSI/VT100 escape sequences?](https://stackoverflow.com/a/35864976/995714) – phuclv Jun 01 '22 at 01:03

1 Answers1

-2

What you need is called ANSI escape sequences for certain colors

Have a look here, I think this is what are you looking for colorful text using printf in C

LexusA
  • 23
  • 3