2

this question helped me to print in different collors.

Iam trying to create a function which always prints the given char*in blue. I got so far:

#define KBLU  "\x1B[34m"
#define KWHT  "\x1B[37m"

void infoPrint(char* msg, ...)
{
    printf("%s", KBLU);
    printf(msg);
    printf("%s", KWHT);
}

When i call the function:

int value = 42;
infoPrint("Show value: %d.\n", value);

Iam getting the following output in the color blue:

Show value: 0.

For any reason the value 42 is not passed correctly.

If i change the function void infoPrint(char* msg, ...)to:

void infoPrint(char* msg, ...)
{
    printf(msg);
}

Iam getting the output (obviously in standard terminal color):

Show value: 42.

What happens to the value 42? Why is it 0 if I try to print in blue before printing the actual message?

Thank you

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
Moritz Schmidt
  • 2,635
  • 3
  • 27
  • 51

0 Answers0