How to underline text using printf in C

It is not possible to do so using any standard C functions, as the C language doesn't even recognize the presence of a screen.

With Windows API console functions you can change colors, underline and some other things. The particular function you are looking for is called SetConsoleTextAttribute just as in the post you linked. Change its attributes to include COMMON_LVB_UNDERSCORE.


You might run your program in some environment with a terminal accepting ANSI escape codes.

(I never used Windows - since I am using Linux only -, so I don't know how to set up such environment in Windows; but I heard that it is possible)

With ANSI escape codes, underlining is "\e[4m" with \e being the ASCII ESCAPE character.