Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

conio.h doesn't contain textcolor()?

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?

like image 751
phillid Avatar asked Mar 12 '26 10:03

phillid


1 Answers

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));
}
like image 145
Alejandro Caro Avatar answered Mar 15 '26 01:03

Alejandro Caro