How to change the color of a console line in C?

-3

So I would like to know how I can change the color of this line ... It's a college project and I've already researched other forums and everything, but I can never find an answer that will work. I am using the DevC ++ (5.11) compiler. When I say change color I mean changing both a single character and an entire string or a vector.

#include <stdio.h>

void main (){


    printf("Ola bom dia!");


    system("pause");
}
    
asked by anonymous 06.11.2018 / 16:22

1 answer

3

You can check out the ANSI escape codes , then use these codes in printf .

So:

#include <stdio.h>

#define VERMELHO     "\x1b[31m"
#define VERDE   "\x1b[32m"
#define AZUL    "\x1b[34m"
#define RESET   "\x1b[0m"

int main () 
{
    printf(VERMELHO     "Texto em vermelho"     RESET "\n");
    printf(VERDE   "Texto em verde"   RESET "\n");
    printf(AZUL    "Texto em azul"    RESET "\n");

    return 0;
}
    
06.11.2018 / 16:30