How to put a color in ONLY a variable in C?

-1

How can I put a color in JUST a variable from my code in C?

I was able to change all colors of ALL of all letters with system("color 02"); with the #include <conio.h> library.

But how do I have multiple colors on the same screen?

For example, how would you put each color name there with your own color on the same screen?

Edit: even if I put multiple system color 02 or textcolor it only changes once the font color and does not allow multiple colors ...

printf("\t\t================ MENU ==================\n");
printf("\n\t\t\tDigite 1 para a cor verde\n");
printf("\t\t\tDigite 2 para a cor azul\n");
printf("\t\t\tDigite 3 para a cor amarelo\n");
printf("\t\t\tDigite 4 para a cor vermelho\n");
printf("\t\t\tDigite 5 para a cor roxo\n");
printf("\t\t\tDigite 6 para a cor marrom\n\n");
printf("\t\t================ MENU ==================\n");
    
asked by anonymous 26.06.2017 / 17:58

1 answer

0

Try this:

#include <stdio.h>

#define RED   "\x1B[31m"
#define GRN   "\x1B[32m"
#define YEL   "\x1B[33m"
#define BLU   "\x1B[34m"
#define MAG   "\x1B[35m"
#define CYN   "\x1B[36m"
#define WHT   "\x1B[37m"
#define RESET "\x1B[0m"

int main()
{
  printf(RED "red\n" RESET);
  printf(GRN "green\n" RESET);
  printf(YEL "yellow\n" RESET);
  printf(BLU "blue\n" RESET);
  printf(MAG "magenta\n" RESET);
  printf(CYN "cyan\n" RESET);
  printf(WHT "white\n" RESET);

  return 0;
}
    
26.06.2017 / 18:57