How to underline text using printf in C

I point out the question Colored text using printf in C gives a good example of setting colored text to standard console output on Windows. Is there something similar that allows the selection to be displayed? Or maybe bold or italics?

EDIT: I tried to answer Lundin on using COMMON_LVB_UNDERSCORE with no luck. Trying to use AddFontResource () to add a cursor in italics in italics to repeat italics gives an error that there is undefined reference to __imp_AddFontResourceA

+6
source share
3 answers

This cannot be done using any standard C functions, since the C language does not even recognize the presence of a screen.

In the functions of the Windows API console, you can change colors, underline, and some other things. The special function you are looking for is called SetConsoleTextAttribute in the same way as in the message you are binding. Change attributes to include COMMON_LVB_UNDERSCORE .

+2
source

You can run your program in some environment with a terminal accepting ANSI cancel codes .

(I never used Windows - since I use only Linux), so I don’t know how to set up such an environment on Windows, but I heard that it is possible)

Using ANSI escape codes, the underscore "\e[4m" with \e is an ESC ASCII character.

+2
source

Perhaps try using termcaps. Something like this (after termcaps initialization):

 printf(tgetstr("us", NULL)); /* underline on */ printf(""/* your string */); printf(tgetstr("ue", NULL)); /* underline off */ 

or more concise:

 printf("%s/* your text here */%s", tgetstr("us", NULL), tgetstr("ue", NULL)); 

https://www.gnu.org/software/termutils/manual/termcap-1.3/html_node/termcap_34.html

+1
source

Source: https://habr.com/ru/post/984545/


All Articles