[comp.lang.c] TC textcolor

timk@xenitec.on.ca (Tim Kuehn) (03/29/90)

This is annoying - I want to display text on my VGA screen in different 
colors. Supposedly the following Turbo C code segment should show me 
a red 'hello' on the screen. It doesn't, but shows me the text in the current 
default color instead:

#include <stdio.h>
#include <conio.h>
#include <dos.h>
 
main()
{
textcolor(RED);
printf("hello\n");
}

-------
I know the computer can do it, becuase the following Turbo PASCAL 
code will show a red 'hello' on the screen like I want:
-------

uses crt, dos;
 
begin
textcolor(RED);
writeln('Hello.');
end.

Am I missing something incredibly obvious, or is this another neat little
"feature" of TC? As near as I can tell, everything is as it's supposed to 
be as a gettextinfo() call returns tinfo.attrib with the proper settings 
that correspond with a color display, and says the text color should be 
red. But the text on the screen isn't red at all.

I'm using an ATI VGA Wonder/512K attached to a NEC 4D on a 386 PC.

Thanks in advance for any assistance!

------------------------------------------------------------------------------
Timothy D. Kuehn 				TDK Consulting Services
871 Victoria St. North, Kitchener, 		voice: (519)-741-3623
Ontario, Canada N2B 3S4			 	DOS/Xenix - SW/HW. uC uP RDBMS
timk@xenitec.on.ca				!watmath!maytag!xenitec!timk
No disclaimer here - I *am* the company!
------------------------------------------------------------------------------

dms@cs.arizona.edu (David Michael Shackelford) (03/30/90)

In article <1990Mar28.224220.16285@xenitec.on.ca>, timk@xenitec.on.ca (Tim Kuehn) writes:
> This is annoying - I want to display text on my VGA screen in different 
> colors. Supposedly the following Turbo C code segment should show me 
> a red 'hello' on the screen. It doesn't, but shows me the text in the current 
> default color instead:
  [ #include's omitted ]   
> main()
> {
> textcolor(RED);
> printf("hello\n");
> }

TC implements a special version of the printf function, cprintf.  It uses
the same arguments as printf, but uses the attributes set by textcolor and
textbackground.  There are also several other 'console' versions of i/o 
functions -- see the reference manual for specifics.

Dave.

dms@cs.arizona.edu

stever@Octopus.COM (Steve Resnick ) (03/30/90)

In article <1990Mar28.224220.16285@xenitec.on.ca> timk@xenitec.UUCP (Tim Kuehn) writes:
>This is annoying - I want to display text on my VGA screen in different 
>colors. Supposedly the following Turbo C code segment should show me 
>a red 'hello' on the screen. It doesn't, but shows me the text in the current 
>default color instead:
>
>#include <stdio.h>
>#include <conio.h>
>#include <dos.h>
> 
>main()
>{
>textcolor(RED);
>printf("hello\n");
>}
>

I'm not sure how textcolor sets the video attribute, whether it's set in
a variable in the conio library or if it actually changes the screen attributes
at the same time. Either way, the ANSI driver is oblivious to this change (where
printf's out put is going) the correct sequence would be:
#include <conio.h>
main()
{
	textcolor(RED);
	cprintf("This oughta work\r\n"); (the \r is needed since this is RAW IO)
}

Hope this helps....