码迷,mamicode.com
首页 > 编程语言 > 详细

C 语言输出不同颜色字体

时间:2019-11-19 17:23:04      阅读:124      评论:0      收藏:0      [点我收藏+]

标签:std   不同   输出   终端   8进制   转义   测试   unix   test   

C 语言输出不同颜色字体

\033是8进制,它就是unix下终端转义符ESC(16进制1A,10进制27)
ESC[xm 是unix下改变终端输出颜色的命令

所以,如果是红色,则我们定义为\033[0;32;31m

以下为测试程序www.cdxsxbx.com

#include <stdio.h>
#define NONE "\033[m"
#define RED "\033[0;32;31m"
#define LIGHT_RED "\033[1;31m"
#define GREEN "\033[0;32;32m"
#define LIGHT_GREEN "\033[1;32m"
#define BLUE "\033[0;32;34m"
#define LIGHT_BLUE "\033[1;34m"
#define DARY_GRAY "\033[1;30m"
#define CYAN "\033[0;36m"
#define LIGHT_CYAN "\033[1;36m"
#define PURPLE "\033[0;35m"
#define LIGHT_PURPLE "\033[1;35m"
#define BROWN "\033[0;33m"
#define YELLOW "\033[1;33m"
#define LIGHT_GRAY "\033[0;37m"
#define WHITE "\033[1;37m"

int main()
{

printf(RED "test1\n"NONE);
printf(LIGHT_RED "test1\n"NONE);
printf(GREEN "test1\n"NONE);
printf(LIGHT_GREEN "test1\n"NONE);
printf(BLUE "test1\n"NONE);
printf(LIGHT_BLUE "test1\n"NONE);
printf(DARY_GRAY "test1\n"NONE);
printf(CYAN "test1\n"NONE);
printf(LIGHT_CYAN "test1\n"NONE);
printf(PURPLE "test1\n"NONE);
printf(LIGHT_PURPLE"test1\n"NONE);
printf(BROWN "test1\n"NONE);
printf(YELLOW "test1\n"NONE);
printf(LIGHT_GRAY "test1\n"NONE);
printf(WHITE "test1\n"NONE);
return 0;
}

C 语言输出不同颜色字体

标签:std   不同   输出   终端   8进制   转义   测试   unix   test   

原文地址:https://www.cnblogs.com/fuoryao/p/11890534.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!