clrscr();
for (i=0; i<9; i++)
{
for (j=0; j<80; j++)
cprintf("C");
cprintf("\r\n");
textcolor(i+1);
textbackground(i);
}
return 0;
}
I use Dev-C++, but I cant to compile this code, this is the reason:
Because conio.h is not part of the C standard. It is a Borland extension, and works only with Borland compilers (and perhaps some other commercial compilers). Dev-C++ uses GCC, the GNU Compiler Collection, as it's compiler. GCC is originally a UNIX compiler, and aims for portability and standards-compliance.
If really can't live without them, you can use Borland functions this way:
Include conio.h to your source, and add C:\Dev-C++\Lib\conio.o to "Linker Options" in Project Options (where C:\Dev-C++ is where you installed Dev-C++).
Please note that conio support is far from perfect. I only wrote it very quickly.
I cant do this: add C:\Dev-C++\Lib\conio.o to "Linker Options" in Project Options (where C:\Dev-C++ is where you installed Dev-C++).
because dont exist conio.o in lib directory.
then, there other way for me have a colored string?
I would suggest using learning C++ instead of C, but it's your choice in the end. Anyway, if you want to make colored text you will have to resort to OS specific functions...you could also try searching for 'colored text' in this forum.
There's also the curses family of libraries, that's designed for output to console, so it has stuff like putting a certain character of a certain color in a certain position in the screen.
Borland Graphics Interface (BGI) for Windows
Version 6.0,
The following functions are mostly from the original Borland Graphics Interface for DOS programs. The BGI graphics functions may also be used with Windows programs created by the Borland 5.0 compiler, the free GNU C++ compiler, and possibly other compilers. Extra Windows functions are also available, described in www.cs.colorado.edu/~main/cs1300/doc/bgi/bgi.html. These extra functions are indicated below by . Also, any of the functions that use colors can use RGB colors in addition to the 16-color BGI palette.
//-----------------------
Description
setcolor sets the current drawing color to color, which can range from 0 to getmaxcolor. The current drawing color is the value to which pixels are set when lines, and so on are drawn. The drawing colors shown below are available for the CGA and EGA, respectively. Name Value :
BLACK 0
BLUE 1
GREEN 2
CYAN 3
RED 4
MAGENTA 5
BROWN 6
LIGHTGRAY 7
DARKGRAY 8
LIGHTBLUE 9
LIGHTGREEN 10
LIGHTCYAN 11
LIGHTRED 12
LIGHTMAGENTA 13
YELLOW 14
WHITE 15
You select a drawing color by passing either the color number itself or the equivalent symbolic name to setcolor. For example, in CGAC0 mode, the palette contains four colors: the background color, light green, light red, and yellow. In this mode, either setcolor(3) or setcolor(CGA_YELLOW) selects a drawing color of yellow.
Return Value
None.
Windows Notes
The winbgim version allows the color argument to be an ordinary BGI color (from 0 to 15) or an RGB color.
I've posted about this function often enough. The latest is here: http://www.cplusplus.com/forum/beginner/5830/
(scroll down for my posts --please don't use system() -- conio.h is a better choice than system() )