a bit of a newbie here. And this seems like a repeated question because others have asked the question. But when i tried the suggested answer it doesn't work for me and idk why. So i have to change the color of the output and these are what i found:
#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;
}
which prints out
[1;31mHello [1;33mworld
as the answer, and i also found this
#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;
}
which prints out
[31mThis text is RED![0m
[32mThis text is GREEN![0m
[33mThis text is YELLOW![0m
[34mThis text is BLUE![0m
[35mThis text is MAGENTA![0m
[36mThis text is CYAN![0m
so it doesn't change any of the colors and just prints them out as they are... why does this happen and how do i color the output?..