Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

colour and ansi C

0 views
Skip to first unread message

Kez404

unread,
Dec 30, 1998, 3:00:00 AM12/30/98
to
Hi *8)

How can I immplement colour into my ansi C programs. ie for an example how can
I change the following program to make each letter in the printf statement a
different colour.

#include <stdio.h>

int main(void)
{
printf( "Colourful man\n" );
return 0;
}

Thanx guys *8)

Kieran Farrell

Charles LaCour

unread,
Dec 30, 1998, 3:00:00 AM12/30/98
to
Color is specific to the platform that you are using. Therefore, there is
no universal ANSI C way to color anything. You will have to find
information for creating colors on your machine from other sources.

--
Increase the Peace!
Charles LaCour
cla...@cwix.com


Kez404 wrote in message <19981230040931...@ng21.aol.com>...

mike burrell

unread,
Dec 30, 1998, 3:00:00 AM12/30/98
to
In article <19981230040931...@ng21.aol.com>,

Kez404 <kez...@aol.comspamless> wrote:
>Hi *8)
>
>How can I immplement colour into my ansi C programs. ie for an example how can
>I change the following program to make each letter in the printf statement a
>different colour.
>
>#include <stdio.h>
>
>int main(void)
>{
> printf( "Colourful man\n" );
> return 0;
>}

one way would be to put in ansi escape characters...ansi escape characters
look something like this:
^[[35mhey ^[[00mthere
where ^[ is ctrl-[ (escape), and [ is just a normal [...35 or 00 is the
colour (35 is foreground magenta, 00 sets everything back to normal), and m
just marks the end of the escape sequence

also you can combine a bunch of them like so:
^[[05;36;41mtest^[[00m
05 makes it blinking, 36 sets it to cyan foreground, and 41 sets it to red
background

anyway hopefully you can find a text which will tell you a bit more about
ansi escape sequences


--
m i k e b u r r e l l
mik...@home.com
http://mikpos.dyndns.org

paolo...@my-dejanews.com

unread,
Dec 30, 1998, 3:00:00 AM12/30/98
to
In article <19981230040931...@ng21.aol.com>,

kez...@aol.comspamless (Kez404) wrote:
> Hi *8)
>
> How can I immplement colour into my ansi C programs. ie for an example how can
> I change the following program to make each letter in the printf statement a
> different colour.

In no way ANSI C compatible. Colour are unknown to the standard.
Ciao Paolo

> #include <stdio.h>
>
> int main(void)
> {
> printf( "Colourful man\n" );
> return 0;
> }
>

> Thanx guys *8)
>
> Kieran Farrell
>

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own

Charles LaCour

unread,
Dec 30, 1998, 3:00:00 AM12/30/98
to
You are assuming the hardware recognizes the escape codes you describe. If
it doesn't, then this method won't work.

--
Increase the Peace!
Charles LaCour
cla...@cwix.com


mike burrell wrote in message ...
>In article <19981230040931...@ng21.aol.com>,


>Kez404 <kez...@aol.comspamless> wrote:
>>Hi *8)
>>
>>How can I immplement colour into my ansi C programs. ie for an example how
can
>>I change the following program to make each letter in the printf statement
a
>>different colour.
>>

>>#include <stdio.h>
>>
>>int main(void)
>>{
>> printf( "Colourful man\n" );
>> return 0;
>>}
>

Graeme Fenwick

unread,
Dec 30, 1998, 3:00:00 AM12/30/98
to
mike burrell wrote in message ...
>In article <19981230040931...@ng21.aol.com>,
>Kez404 <kez...@aol.comspamless> wrote:
>>How can I immplement colour into my ansi C programs.
>one way would be to put in ansi escape characters...ansi escape characters


ANSI escape characters aren't a part of ANSI C. Daft but true.

============================================
Graeme Fenwick | gfen...@BYESPAMprimex.co.uk

"Please remove BYESPAM filter when replying by mail"
-- WILLIAM SHAKESPEARE, Hamlet.

Kez404

unread,
Dec 30, 1998, 3:00:00 AM12/30/98
to
Well that's just grand isn't it, a language people claim to be the most
powerful and flexible yet I can't do a simple thing like have coloured text.
This isn't a programming language it's a joke. Even pascal can do more than
this crappy code base. I will not accept that there is no way to do it, I've
put too much into learning C to have the rug pulled out from underneath me!! If
anyone can help me I'll appreciate it otherwise I'm giving C away for a code
base that can do the job. like BASIC!!! (insults intended)

Matt Weber

unread,
Dec 30, 1998, 3:00:00 AM12/30/98
to
In article <19981230181758...@ng18.aol.com>,
kez...@aol.comspamless says...

What 'job' are you talking about? If you want colored text you simply
have to compile different versions of your programs and indicate for
which platform they are designed to run. Colored text is possible, not
portable.

-matt
--
{Matt Weber}
{mrw...@erols.com}
"The horror ... the horror" - Col. Kurtz

Ben Pfaff

unread,
Dec 30, 1998, 3:00:00 AM12/30/98
to
kez...@aol.comspamless (Kez404) writes:

Well that's just grand isn't it, a language people claim to be the most
powerful and flexible yet I can't do a simple thing like have coloured text.
This isn't a programming language it's a joke. Even pascal can do more than
this crappy code base. I will not accept that there is no way to do it, I've
put too much into learning C to have the rug pulled out from underneath me!! If
anyone can help me I'll appreciate it otherwise I'm giving C away for a code
base that can do the job. like BASIC!!! (insults intended)

I'll say it again. ANSI C has no support for color text. Now go play
in comp.os.msdos.programmer.
--
(supporter of the campaign for grumpiness where grumpiness is due in c.l.c)

Please: do not email me copies of your posts to comp.lang.c
do not ask me C questions via email; post them instead

Martin Ambuhl

unread,
Dec 30, 1998, 3:00:00 AM12/30/98
to
Kez404 wrote:
>
> Well that's just grand isn't it, a language people claim to be the most
> powerful and flexible yet I can't do a simple thing like have coloured text.
> This isn't a programming language it's a joke. Even pascal can do more than
> this crappy code base. I will not accept that there is no way to do it, I've
> put too much into learning C to have the rug pulled out from underneath me!! If
> anyone can help me I'll appreciate it otherwise I'm giving C away for a code
> base that can do the job. like BASIC!!! (insults intended)

Unfortunately, the clueless cannot even formulate insults. We know,
unlike you, that neither BASIC nor Pascal can do what you want. No
doubt you have suffered at the hands of implementations that never told
you that you were using non-standard, non-portable,
implementation-defined additions to the language. I look in my Turbo
Pascal 7 docs and find no reference to which implementations support
what.
In standard C, just as in standard Pscal, there is no way provided in
the language for doing what you want. In standard C, as in standard
Pascal, you accomplish these with non-standard functionality provided
either by your implementation or by a 3rd party. For maximum
portability in C, use curses. For maximum portability in Pascal, shoot
your brains out.

--
Martin Ambuhl (mam...@earthlink.net)
Note: mam...@tiac.net will soon be inactive


Mathew Hendry

unread,
Dec 31, 1998, 3:00:00 AM12/31/98
to
On 30 Dec 1998 23:17:58 GMT, kez...@aol.com (Kez404) wrote:

>Well that's just grand isn't it, a language people claim to be the most
>powerful and flexible yet I can't do a simple thing like have coloured text.

Of course it can, but you'll need to work at it. Look for an
implementation of the "curses" library for your machine. It does
colours, cursor positioning and all sorts of other |<-rad text type
stuff.

>This isn't a programming language it's a joke. Even pascal can do more than
>this crappy code base.

Which non-standard, unsupported, proprietary variant of Pascal would
that be?

> I will not accept that there is no way to do it, I've
>put too much into learning C to have the rug pulled out from underneath me!! If
>anyone can help me I'll appreciate it otherwise I'm giving C away for a code
>base that can do the job. like BASIC!!! (insults intended)

Visual Basic sounds like just what you're after. Colourful, but not
very portable. Good luck!

-- Mat.


Will Rose

unread,
Dec 31, 1998, 3:00:00 AM12/31/98
to
Kez404 (kez...@aol.comspamless) wrote:
: Well that's just grand isn't it, a language people claim to be the most
: powerful and flexible yet I can't do a simple thing like have coloured text.
: This isn't a programming language it's a joke. Even pascal can do more than
: this crappy code base. I will not accept that there is no way to do it, I've

: put too much into learning C to have the rug pulled out from underneath me!! If
: anyone can help me I'll appreciate it otherwise I'm giving C away for a code
: base that can do the job. like BASIC!!! (insults intended)

Depending on what you are doing, and what system you are using to do it,
Visual Basic might well be a better bet. I used it for some rapid
prototyping (a while back) and it was pretty straightforward, and of
course in color.

C is powerful, but has no idea of colors or indeed graphics of any
description. You need a terminal-handling or graphics library
(eg. OpenGL); what you use will again depend on your system. Try
asking in a system-related newsgroup, since someone will have solved
this problem before.


Will
c...@crash.cts.com


Jack Klein

unread,
Dec 31, 1998, 3:00:00 AM12/31/98
to
On 30 Dec 1998 23:17:58 GMT, kez...@aol.comspamless (Kez404) wrote:

> Well that's just grand isn't it, a language people claim to be the most
> powerful and flexible yet I can't do a simple thing like have coloured text.
> This isn't a programming language it's a joke. Even pascal can do more than
> this crappy code base. I will not accept that there is no way to do it, I've
> put too much into learning C to have the rug pulled out from underneath me!! If
> anyone can help me I'll appreciate it otherwise I'm giving C away for a code
> base that can do the job. like BASIC!!! (insults intended)

<Jack>

Yes, please give away your C compiler and forget the name of this
group.

</Jack>
--
Do not email me with questions about programming.
Post them to the appropriate newsgroup.
Followups to my posts are welcome.


Andy & Deobrah Bretten

unread,
Dec 31, 1998, 3:00:00 AM12/31/98
to
A quite portable way of including colour into a C program is an
approach I used once, it takes quite a lot of work but I think its
pretty worthwhile. The program acts as a telnet server using some
simple socket code, then you telnet into the server, which takes input
to do whatever it is the program is suppose to do. Then you just
output whatever it is you want to output to the connected sockets with
ansi codes in their appropriate places.....Then all you need is a
colour xterm or Gmud on Win 95, or Ewan on win 3.1?, etc ie a telnet
proggy with colour for whatever platform.....the C program just
happily runs whereever you compile it.

Andy P Bretten - bre...@fuse.net

On Wed, 30 Dec 1998 19:34:12 GMT, "Charles LaCour" <cla...@cwix.com>
wrote:

Charles LaCour

unread,
Dec 31, 1998, 3:00:00 AM12/31/98
to
It sounds as though you are simply proving my point. You can certainly
embed control codes into an ANSI C program and the program itself will be
ANSI compliant since the string values don't matter with respect to ANSI
compliance. However, the device receiving the ANSI codes must be able to
interpret them, or they will be ignored.

--
Increase the Peace!
Charles LaCour
cla...@cwix.com


Andy & Deobrah Bretten wrote in message <368b233...@news.fuse.net>...

Reg Braddock

unread,
Dec 31, 1998, 3:00:00 AM12/31/98
to
On 30 Dec 1998 23:17:58 GMT, Kez404 <kez...@aol.comspamless> wrote:
>Well that's just grand isn't it, a language people claim to be the most
>powerful and flexible yet I can't do a simple thing like have coloured text.
>This isn't a programming language it's a joke. Even pascal can do more than
>this crappy code base. I will not accept that there is no way to do it, I've
>put too much into learning C to have the rug pulled out from
....

>anyone can help me I'll appreciate it otherwise I'm giving C away for a code
>base that can do the job. like BASIC!!! (insults intended)

I think that you are confusing ANSI C (a language specification) with
ANSI terminals (a terminal specification). There is no connection
besides the standards body that oversaw the spec.

What you are asking for is impossible to put into the specification of
a portable language. What if your program runs on a computer without
a colour display? What of the various GUIs? Any language that
includes this in the standard specification is a joke because it is
incapable of being transferred from machine to machine. This type of
feature is best added on by means of a library of functions that deals
with the ANSI escape codes if you wish to write your program for a
computer with that sort of display. There should be a few out there.

Reg.


--
----------------------------------------------------------------------
"It is not always the same thing to be a good man and a good citizen."
Aristotle.

Graeme Fenwick

unread,
Dec 31, 1998, 3:00:00 AM12/31/98
to
Kez404 wrote in message <19981230181758...@ng18.aol.com>...

>Well that's just grand isn't it, a language people claim to be the most
>powerful and flexible yet I can't do a simple thing like have coloured
text.

Yes you can. You can do anything your particular compiler supports- but
you'll have to rewrite the non-ANSI parts (i.e. the coloured text in this
case) if you want to port it. How is having a standard that you can write
most of your program in inferior to nothing at all?

>This isn't a programming language it's a joke.

Is this a troll, or what?

>Even pascal can do more than this crappy code base.

Okay- use Pascal if you like.

>I will not accept that there is no way to do it, I've

>put too much into learning C to have the rug pulled out from underneath
me!!

You spent all that time learning C, and you still don't understand why the
ANSI standard is so important. Where the heck did you learn it from?

>If anyone can help me I'll appreciate it otherwise I'm giving C away for a


code
>base that can do the job. like BASIC!!! (insults intended)


Okay then. What job would that be? (No insult required).

William McBrine

unread,
Dec 31, 1998, 3:00:00 AM12/31/98
to
Most portable way to do color codes in C: use an implementation of the
curses library. Versions exist for Unix, DOS, OS/2, Win/32, Amiga, etc.

--
William McBrine | http://www.clark.net/~wmcbrine/
wmcb...@clark.net | ./\./\./\./\./\./\./\./\./\./\.

Peter Shaggy Haywood

unread,
Jan 1, 1999, 3:00:00 AM1/1/99
to
Groovy hepcat Kez404 was jivin' on 30 Dec 1998 23:17:58 GMT in
comp.lang.c.
Re: colour and ansi C's a cool scene! Dig it!

>Well that's just grand isn't it, a language people claim to be the most
>powerful and flexible yet I can't do a simple thing like have coloured text.

>This isn't a programming language it's a joke. Even pascal can do more than
>this crappy code base. I will not accept that there is no way to do it, I've
>put too much into learning C to have the rug pulled out from underneath me!! If


>anyone can help me I'll appreciate it otherwise I'm giving C away for a code
>base that can do the job. like BASIC!!! (insults intended)

Kez404, please don't come here and badmouth the language in which we
program. Most of us here have no problems with C (appart from the
difficulties in learning the intricasies of this language). In fact,
we love it.
The problem of coloured text in C programs is not impossible to
solve. There are perfectly simple ways to achiev this goal. However,
such things are dependant on the system for which a program is
written. Standard C is designed to be useable on as many systems as
possible, some of which don't support coloured output. This means that
standard C cannot support such system specifics as colour.
If you'd like to ask your question again in a more apropriate group,
such as comp.os.msdos.programmer (if you're programming for DOS),
you're more likely to get a useful answer. Then you'll see how
powerful C can be.
--

----- Dig the EVEN NEWER, MORE IMPROVED news sig!! -----

-------------- Shaggy was here! ---------------
http://aardvark.apana.org.au/~phaywood/
============= Ain't I'm a dawg!! ==============


Bryn Joynes

unread,
Jan 3, 1999, 3:00:00 AM1/3/99
to Kez404
Hi,

I suggest you have a look at this web page, especially if you are
working in DOS, if you are not working in DOS sorry for the bandwidth.
http://www.c-for-dummies.com/lessons/chapter.13/05/

Another thing if you are working in DOS, try Borlands Turbo C++ 3.0, it
has some video functions that will do what you want in C I believe. $89
will get you Borlands Turbo C++ suite, with C++ Builder, C++ 4.5 for
Windows and C==3.0 for DOS.

Best Regards

Bryn Joynes.......


Kez404 wrote:
>
> Well that's just grand isn't it, a language people claim to be the most
> powerful and flexible yet I can't do a simple thing like have coloured text.

--
To reply to my e-mail, remove the REMOVE from my e-mail address. Thank
You.
Bryn Joynes

Kez404

unread,
Jan 4, 1999, 3:00:00 AM1/4/99
to
First of all I would like to appologize whole heartedly to the group for my
ignorant flames, they were brought on by my frustration and I pushed send
before I could think clearly enough to stop myself. Very strange for me to act
like that, I'm sorry.

Secondly I would like to thank Bryn for pointing me to a web page that helped
me.

*8)

Kieran Farrell

Andy & Deobrah Bretten

unread,
Jan 5, 1999, 3:00:00 AM1/5/99
to
My point is though....you can write such a program in ANSI C without
any portability problems.....assuming you can cope with the socket
code, though that really kicks off another debate about writing C for
unix or dos or windoze etc which I dont think anyone needs rehashed.

(observation here: i'd be able to grab this newsgroup 3 times faster
if 10 people didn't all flame the same post for being non-related to
the newsgroup).

All you have to worry about is using a terminal that supports ANSI
codes but then its not a writing C issue...its a finding a program
issue. So yes it does prove your point.....but it also offers a way
around the problem/question put forward....isn't that the purpose of
us all reading/posting these messages ?

Andy P Bretten - bre...@fuse.net

On Thu, 31 Dec 1998 09:58:28 GMT, "Charles LaCour" <cla...@cwix.com>

J. Benz

unread,
Jan 5, 1999, 3:00:00 AM1/5/99
to

Andy & Deobrah Bretten wrote:

> (observation here: i'd be able to grab this newsgroup 3 times faster
> if 10 people didn't all flame the same post for being non-related to
> the newsgroup).
>

observation here - we're not all sitting in the same room. Duh. When I see a
new Bretten post, I have no idea who else out there - in the rest of the world
- might be crafting up an elegant and pithy flame for you, or who might have
already sent one that just hasn't shown up on my server yet. So we all see
ourselves as the first flame, and the multiples don't even show up until the
next day, usually. Would you prefer we sent the flames to your e-mail
account? Don't even go there.


Lawrence Kirby

unread,
Jan 6, 1999, 3:00:00 AM1/6/99
to
In article <369247cb...@news.fuse.net>

bre...@fuse.net "Andy & Deobrah Bretten" writes:

>My point is though....you can write such a program in ANSI C without
>any portability problems.....assuming you can cope with the socket
>code, though that really kicks off another debate about writing C for
>unix or dos or windoze etc which I dont think anyone needs rehashed.

The point is that if you are writing socket code you aren't writing in
standard C, the code will not be portable.

--
-----------------------------------------
Lawrence Kirby | fr...@genesis.demon.co.uk
Wilts, England | 7073...@compuserve.com
-----------------------------------------


Peter Shaggy Haywood

unread,
Jan 8, 1999, 3:00:00 AM1/8/99
to
Groovy hepcat Andy & Deobrah Bretten was jivin' on Tue, 05 Jan 1999
17:14:46 GMT in comp.lang.c.

Re: colour and ansi C's a cool scene! Dig it!

>My point is though....you can write such a program in ANSI C without


>any portability problems.....assuming you can cope with the socket

Well, yes. You won't have any problems compiling such a program. But
there's more to portability than compiling. The program just won't run
under all circumstances, and that's what makes it non-portable.

0 new messages