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.
Asked
Active
Viewed 5,899 times
1

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

Rusu Florin Andrei
- 49
- 1
- 10
1 Answers
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.
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
-
If this solves your query.Mark the answer as accepted. – Shvet Chakra Nov 30 '15 at 15:57
-
It's just..neither CodeBlocks or Microsoft Visual Studio recognize the textcolor function.. – Rusu Florin Andrei Dec 01 '15 at 11:50
-
specifically if you want to do it in Code Block then follow the following link , it might be helpful [link](http://stackoverflow.com/questions/29574849/how-to-change-text-color-and-console-color-in-codeblocks) – Shvet Chakra Dec 01 '15 at 14:34
-
Thanks! You, sir, are a life saver :)) – Rusu Florin Andrei Dec 01 '15 at 15:00