How can I print a red "Hello world"

G

Gestorm

It seems that the standard c library doesn't give any support on
this. I googled this question and found that the code would not be
portable. Then how can I do this under linux ? Thanks! ^_^
 
K

Keith Thompson

Gestorm said:
It seems that the standard c library doesn't give any support on
this. I googled this question and found that the code would not be
portable. Then how can I do this under linux ? Thanks! ^_^

You can start by asking in a Linux-specific newsgroup.

(Note that this might not be possible under Linux, depending on the
nature of the terminal or terminal emulator you're using.)
 
V

viza

It seems that the standard c library doesn't give any support on this.
I googled this question and found that the code would not be portable.
Then how can I do this under linux ? Thanks! ^_^

It is not a Linux specific thing it is a terminal type specific thing.
On my terminal I can use:

fputs( "\033[31mHello World!\n", stdout );

Lookup the different codes on:
http://www.ibm.com/developerworks/linux/library/l-tip-prompt/

in particular, lookup the code for how to reset it back to what might be
the "correct" colour. My PS1 (prompt) variable does this for me so I
haven't included it above.

If you want to play with this sort of thing, remember that when you screw
up your terminal, you can usually type reset[enter] to get it back, and
this usually works even if you can't see the letters coming up.
 
G

Gestorm

It is not a Linux specific thing it is a terminal type specific thing.
On my terminal I can use:

fputs( "\033[31mHello World!\n", stdout );

Lookup the different codes on:http://www.ibm.com/developerworks/linux/library/l-tip-prompt/

in particular, lookup the code for how to reset it back to what might be
the "correct" colour. My PS1 (prompt) variable does this for me so I
haven't included it above.

If you want to play with this sort of thing, remember that when you screw
up your terminal, you can usually type reset[enter] to get it back, and
this usually works even if you can't see the letters coming up.

Very helpful, thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top