实例1
#include <stdio.h>int main(){printf("\033[0;37m%s \033[0m\n","linux");printf("\033[0;36m%s \033[0m\n","linux");printf("\033[0;35m%s \033[0m\n","linux");printf("\033[0;34m%s \033[0m\n","linux");printf("\033[0;30m%s \033[0m\n","linux");printf("\033[40;37m%s \033[0m\n","linux");printf("\033[41;36m%s \033[0m\n","linux");printf("\033[42;35m%s \033[0m\n","linux");printf("\033[43;34m%s \033[0m\n","linux");printf("\033[44;33m%s \033[0m\n","linux");return 0;}
[root@localhost color]# vi color2.c
[root@localhost color]# gcc color2.c -o color2
[root@localhost color]# ./color2
结果如下
实例2:
#include <stdio.h>int main(){printf("\033[0;37m%s \033[0m\n","linux");printf("\033[0;36m%s \033[0m\n","linux");printf("\033[0;35m%s \033[0m\n","linux");printf("\033[0;34m%s \033[0m\n","linux");printf("\033[0;30m%s \033[0m\n","linux");printf("\033[40;37m%s \033[0m\n","linux");printf("\033[41;36m%s \033[0m\n","linux");printf("\033[42;35m%s \033[0m\n","linux");printf("\033[43;34m%s \033[0m\n","linux");printf("\033[44;33m%s \033[0m\n","linux");printf("\033[44;33m%s\n","linux");printf("\033[44;33m%s \033[0m\n","linux");return 0;}
[root@localhost color]# vi color2.c
[root@localhost color]# gcc color2.c -o color2
[root@localhost color]# ./color2
结果如下
\033 是E的asc码,而这种是一个标记对,\033 是成对存在的.当然可以把E代替成\033
\033[ 后面的第一个参数是关闭所有文字的效果。
第二个参数是字体以及字体背景的颜色:
30—-黑色 31—-红色 32—-绿色 33—-黄色
34—-蓝色 35—-紫色 36—-墨绿 37~39—-白色
字体的背景色:
40—-黑色 41—-红色 42—-绿色 43—-黄色
44—-蓝色 45—-紫色 46—-墨绿色 47—-白色
第三个参数是字体的效果:
效果分为:
1—-高亮 4—-下划线 5—-闪烁 7—–背景取反 2J—-清屏