Reputation: 49
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.
Upvotes: 1
Views: 6110
Reputation: 1043
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.
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.
Upvotes: 1