textcolor() 函数在 conio.h 头文件中定义。此函数有助于更改打印文本的颜色。
void textcolor(int color); #color must be written in all caps, or expressed as a interger value:
textcolor() 函数接受单个参数“color”,它是一个整数变量,用于保存给定颜色的相应整数值。
| 参数 | 描述 | 必需/可选 |
|---|---|---|
| 颜色 | 它具有整数值或者颜色必须全部大写 | 必需 |
| 颜色 | 值 |
|---|---|
| 黑色 | 0 |
| 蓝色 | 1 |
| 绿色 | 2 |
| 青色 | 3 |
| 红色 | 4 |
| 洋红色 | 5 |
| 棕色 | 6 |
| 浅灰色 | 7 |
| 深灰色 | 8 |
| 浅蓝色 | 9 |
| 浅绿色 | 10 |
| 浅青色 | 11 |
| 浅红色 | 12 |
| 浅洋红色 | 13 |
| 黄色 | 14 |
| 白色 | 15 |
textcolor() 函数不返回任何值,它只更改文本颜色。
#include <stdio.h>
#include <conio.h>
int main()
{
// setting the color of text
textcolor(GREEN); /// You could type "2" instead of "GREEN", but it is not as readable
cprintf("Change the text colour to green");
getch();
return 0;
}
输出
Change the text colour to green /* with green textcolor */
#include <stdio.h>
#include <conio.h>
int main()
{
textcolor(BLUE+BLINK);
cprintf("Making text with a blue blinking text");
getch();
return 0;
}
输出
Making text with a blue blinking text /* with blue blinking */