0

I tried the system("COLOR 0a"); but it will change all the font color to that color. I also tried the textcolor(4) it gives me an error, the error message is textcolor is undeclared but I include the conio.h. What the problem?

NOTE: Im using windows 7 as an operating system

My codes

#include<stdio.h>
#include<conio.h>
int main()
{
    textcolor(4);
    cprintf("dkfjdk");
    return 0;
}
Diti
  • 1,454
  • 3
  • 23
  • 38

2 Answers2

1

You can use the Windows function SetConsoleTextAttribute. A list of attributes is here.

The following will print "hello world" in bright red. Note that you'll want to reset the colour to the default (grey) if you want to print something else in grey afterwards.

fflush(stdout);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_INTENSITY));
printf("hello world\n");

Note: The first call to fflush(stdout) is to ensure that any previously printed text appears in grey.

Note: make sure to #include <windows.h>

user253751
  • 57,427
  • 7
  • 48
  • 90
  • I got error it said expected ; before ) where is it? SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_INTENSITY)); – WatchaGonnaDo Oct 05 '16 at 02:14
  • 1
    @WatchaGonnaDo Aha, the typo in this answer was *totally* intentional, I swear. If you know C then you should be able to find the mistake in that line yourself. – user253751 Oct 05 '16 at 02:14
0

try textcolor(blue);

code-reference.com/c/conio.h/textcolor
ST3
  • 8,826
  • 3
  • 68
  • 92
matt
  • 1