0

Is there anyway to make a printf and have only a certain part of the text displayed in the console in colour?

For example, let's say I'm about to print:

printf("a b c");

Is there anyway to print only one of those letters in colour? Can I have an output in the Windows console that only displays one of them in colour? If so, how should I do it and what library should I use?

1 Answers1

0

You could use windows console API, for example the function SetConsoleTextAttribute():

#include <windows.h>
...
   SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
                        BACKGROUND_INTENSITY|FOREGROUND_BLUE); 

You would have to make such kind of calls to set attributes every time you want to change them before doing the printf(). But be careful: this function is specific to windows and not portable.

Christophe
  • 68,716
  • 7
  • 72
  • 138