I've been looking at using colours in a DOS program I'm writing in C. I was told that conio.h has the textcolor() function, but when I use it in my code, the compiler/linker throws errors at me saying I've an undefined reference to the function.
Does conio.h actually have this function or have I been told bull?
No, the conio.h library does not have the textcolor function defined. One of the ways that that function could be defined is the following (include the windows.h library):
void textcolor (int color)
{
static int __BACKGROUND;
HANDLE h = GetStdHandle ( STD_OUTPUT_HANDLE );
CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
GetConsoleScreenBufferInfo(h, &csbiInfo);
SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),
color + (__BACKGROUND << 4));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With