1

Is there any way to change the color in the console of a specific character? I'm using code blocks and, for example, I want to change the color of all @ to red and all o to yellow.

Bjørn-Roger Kringsjå
  • 9,849
  • 6
  • 36
  • 64

1 Answers1

1

You have to write a different function to achieve this task. I am adding a code to show how it can be done in C.`

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>

void output(char *s)
{
int i=0;
while(*(s+i) !='\0')
{
    if(*(s+i)=='@')
   {
   textcolor(RED);
    cprintf("%c",*(s+i));
   }
   else if(*(s+i) =='.')
   {
    textcolor(YELLOW);
    cprintf("%c",*(s+i));
   }
   else
   {
   textcolor(WHITE);
   cprintf("%c",*(s+i));
   }
   i++;
}
}
void main()
{
char S[]="@shvet.";
output(S);
getch();
}

Here is the image for the output console window. Output

Note that I have used cprintf function instead of printf. This is because cprintf send formatted output to text window on screen and printf sends it to stdin.

Shvet Chakra
  • 1,043
  • 10
  • 21