Making some text in printf appear in green and red

后端 未结 2 574
离开以前
离开以前 2020-12-22 20:11

linux gcc 4.4.1

I have the following fprintf statement and I would like to have the OK as green and the FAILED as red. Is this possible?

if(devh == -         


        
2条回答
  •  时光说笑
    2020-12-22 20:55

    You should probably use some library such as ncurses to handle terminal.

    Alternatively, under Linux you could use some console escape sequences such as:

    printf ("\033[32;1m OK \033[0m\n");
    

    (in this case 32 stands for green), but it is neither portable nor elegant.

提交回复
热议问题