PDA

View Full Version : Problem with [colortext()] and [textbackground()]



Goof Program
03-21-2002, 11:43 AM
Why does [cprintf()] not work the same way as [printf()]?

Please compile my code and see what I mean.



#include <stdio.h>
#include <conio.h>

int main(void)
{

printf("1. This is the normal dos colors.\n");
printf("2. This is right below.\n");
printf("3. This is under \"This is right below.\"\n");
printf("4. and this is the last part\n\n");


textcolor(BLUE);
cprintf("1. This should be the color: BLUE.");

printf("2. This should be right below the BLUE text.");

textcolor(LIGHTGRAY);
textbackground(BLUE);
cprintf("3. This should have a BLUE background.");

getchar();

return 0;
}

alex
03-21-2002, 12:00 PM
Originally posted by Goof Program
Why does [cprintf()] not work the same way as [printf()]?

(Borlands) cprintf does not use dos to write to the screen, but writes directly to video memory (or uses bios calls, depending on a global variable). This makes it faster and also introduces the possibility to use color efficiently. Dos has no provision for using color. The output of cprintf cannot be redirected to a file (using | or > on the dos command line). There is another difference: cprintf interprets "\n" as a line feed only, while printf automatically prepends a carriage return ("\r").

Hope this helps...
alex

Goof Program
03-21-2002, 12:06 PM
I have one last question. If I do [cprintf("text here\r");] is that the same as [printf("text here\n");]?

Thanks

alex
03-21-2002, 12:11 PM
Almost...

cprintf("text here\r\n");
should look the same as
printf("text here\n");
except for the color of course.

greetinx,
alex

Goof Program
03-21-2002, 12:14 PM
Thanks for the help, It has made my coding easyer.

Jperensky
03-29-2002, 09:35 PM
How would I go about making a full screen program in DOS that has a specified Background color and all that good stuff... not just text colors and text backgrounds?

Jperensky
03-29-2002, 10:29 PM
Is there any way to go back to the original DOS colors (light grey and black) without manually redefining textbackground and text color and placing another cprintf() function in the program?

ihsir
03-29-2002, 11:21 PM
i use the foll statements to do that

---
---
textcolor(7); /orig colors
clrscr();
---
---

Also, the "cls" command puts it back to normal

sean
04-03-2002, 10:33 AM
The main difference which should answer all your questions, is that in ASM, there's text (usually int 21), and video (a WHOLE bunch of other stuff), which is more specialized to graphics. cprintf uses video, and printf uses the text, so if you need something special that neither of these offer, the ASM is where it all comes from.