LINUX C语言 printf 输出颜色 属性控制 打印带颜色字体(简单易理解)printf带0X前缀输出控制

很早之前有用过一次颜色控制,查阅资料摸索半天  最近用到又忘记怎么用了 所以调试了半天就直接写一个可随时复制使用的吧

这是效果图

通用代码

/*************************************************************************                              
    > File Name: color.c
    > Author: TANG
    > Mail: tjcmail@126.com 
    > Created Time: 2018年05月16日 星期三 10时13分58秒
 ************************************************************************/

/*设置输出前景色*/
#define PRINT_FONT_BLA  printf("\033[30m"); //黑色
#define PRINT_FONT_RED  printf("\033[31m"); //红色
#define PRINT_FONT_GRE  printf("\033[32m"); //绿色
#define PRINT_FONT_YEL  printf("\033[33m"); //黄色
#define PRINT_FONT_BLU  printf("\033[34m"); //蓝色
#define PRINT_FONT_PUR  printf("\033[35m"); //紫色
#define PRINT_FONT_CYA  printf("\033[36m"); //青色
#define PRINT_FONT_WHI  printf("\033[37m"); //白色
/*设置输出背景色*/ 
#define PRINT_BACK_BLA  printf("\033[40m"); //黑色
#define PRINT_BACK_RED  printf("\033[41m"); //红色
#define PRINT_BACK_GRE  printf("\033[42m"); //绿色
#define PRINT_BACK_YEL  printf("\033[43m"); //黄色
#define PRINT_BACK_BLU  printf("\033[44m"); //蓝色
#define PRINT_BACK_PUR  printf("\033[45m"); //紫色
#define PRINT_BACK_CYA  printf("\033[46m"); //青色
#define PRINT_BACK_WHI  printf("\033[47m"); //白色
/*输出属性设置*/
#define PRINT_ATTR_REC  printf("\033[0m");  //重新设置属性到缺省设置 
#define PRINT_ATTR_BOL  printf("\033[1m");  //设置粗体 
#define PRINT_ATTR_LIG  printf("\033[2m");  //设置一半亮度(模拟彩色显示器的颜色) 
#define PRINT_ATTR_LIN  printf("\033[4m");  //设置下划线(模拟彩色显示器的颜色) 
#define PRINT_ATTR_GLI  printf("\033[5m");  //设置闪烁 
#define PRINT_ATTR_REV  printf("\033[7m");  //设置反向图象 
#define PRINT_ATTR_THI  printf("\033[22m"); //设置一般密度 
#define PRINT_ATTR_ULIN  printf("\033[24m");//关闭下划线 
#define PRINT_ATTR_UGLI  printf("\033[25m");//关闭闪烁 
#define PRINT_ATTR_UREV  printf("\033[27m");//关闭反向图象

#include <stdio.h>
int main()
{
    PRINT_FONT_BLA  
    printf("hello world!\n");
    
    PRINT_FONT_BLU
    printf("hello world!\n");
    
    PRINT_FONT_RED 
    printf("hello world!\n");
    
    PRINT_FONT_YEL 
    printf("hello world!\n");                                                                           

    
    PRINT_FONT_GRE 
    printf("hello world!\n");
    
    PRINT_FONT_WHI 
    printf("hello world!\n");
    
    PRINT_FONT_PUR 
    printf("hello world!\n");
    
    PRINT_ATTR_REV
    printf("hello world!\n");
    
    PRINT_ATTR_REC
    return 0;
}  

printf十六进制输出

    printf("%#X",sum);//'#'意义:在数字前边加上'0X'

printf八进制输出

    printf("%o\n",sum);

  • 8
    点赞
  • 32
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

我是唐

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值