Is there a way to color the text displayed on screen for a program in C
Is there a way to color the text displayed on screen for a program in C
Like in a windows or dos
if your doing it in a borland compiler you can use the command
cprintf (contained in the conio.h file) and use something like:
textcolor(7);
and
textbackground(0);
to change the color of the writing to that specified in the brackets, but this is a non standard way so all depends on what you need it for, etc.
It's for a DOS program. I'm using Bloodshed Dev-C++ compiler. Can you give me an example using the textcolor(7) and textbacground(0) please if you can.
Thanks
i dont understand, it is simply those commands so if you wanted the text to be red you'd do:
[code]
#include <conio.h>
int main()
{
textcolor(3);
cprintf("\nTHIS TEXT IS RED\n");
textcolor(18);
cprintf("\nI THINK THIS IS FLASHING RED\n");
}
just have a play with it, hopefully its what your after, this command should also be in the help within borland to find out the exact numbers for each color.
I tryed to compile in Dev-C++ and Miracle C but in Dev-C++ I get
"[Linker error] undefined reference to `textcolor'"
and some other error in Miracle C. What's going on?
Shouldent NULL be, 78, 85, 76, 76, or just 0 or, 4E, 55, 4C, 4C
I have the right header in too. And my compiler supports conio.h
Shouldent NULL be, 78, 85, 76, 76, or just 0 or, 4E, 55, 4C, 4C
I'm guessing your compiler or version of conio.h doesnt support textcolor, if you have a look or do a file search for anything that contains the words color or colour, then maybe you might find something in the .h files.
here's whats in my conio.h when I opened it. It has stuff about color but I dont know what some of it means.
#ifndef _CONIO_H_
#define _CONIO_H_
#include <stdio.h>
#ifdef __cplusplus
extern "C" {
#endif
#define BLINK 0
typedef enum
{
BLACK,
BLUE,
GREEN,
CYAN,
RED,
MAGENTA,
BROWN,
LIGHTGRAY,
DARKGRAY,
LIGHTBLUE,
LIGHTGREEN,
LIGHTCYAN,
LIGHTRED,
LIGHTMAGENTA,
YELLOW,
WHITE
} COLORS;
#define cgets _cgets
#define cprintf _cprintf
#define cputs _cputs
#define cscanf _cscanf
#define ScreenClear clrscr
/* blinkvideo */
void clreol (void);
void clrscr (void);
int _conio_gettext (int left, int top, int right, int bottom,
char *str);
/* _conio_kbhit */
void delline (void);
/* gettextinfo */
void gotoxy(int x, int y);
/*
highvideo
insline
intensevideo
lowvideo
movetext
normvideo
*/
void puttext (int left, int top, int right, int bottom, char *str);
// Screen Variables
/* ScreenCols
ScreenGetChar
ScreenGetCursor
ScreenMode
ScreenPutChar
ScreenPutString
ScreenRetrieve
ScreenRows
ScreenSetCursor
ScreenUpdate
ScreenUpdateLine
ScreenVisualBell
_set_screen_lines */
void _setcursortype (int type);
void textattr (int _attr);
void textbackground (int color);
void textcolor (int color);
/* textmode */
int wherex (void);
int wherey (void);
/* window */
/* The code below was part of Mingw's conio.h */
/*
* conio.h
*
* Low level console I/O functions. Pretty please try to use the ANSI
* standard ones if you are writing new code.
*
* This file is part of the Mingw32 package.
*
* Contributors:
* Created by Colin Peters <[email protected]>
*
* THIS SOFTWARE IS NOT COPYRIGHTED
*
* This source code is offered for use in the public domain. You may
* use, modify or distribute it freely.
*
* This code is distributed in the hope that it will be useful but
* WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
* DISCLAMED. This includes but is not limited to warranties of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* $Revision: 1.4 $
* $Author: hongli $
* $Date: 2002/04/26 19:31:25 $
*
*/
char* _cgets (char*);
int _cprintf (const char*, ...);
int _cputs (const char*);
int _cscanf (char*, ...);
int _getch (void);
int _getche (void);
int _kbhit (void);
int _putch (int);
int _ungetch (int);
int getch (void);
int getche (void);
int kbhit (void);
int putch (int);
int ungetch (int);
#ifdef __cplusplus
}
#endif
#endif /* _CONIO_H_ */
Shouldent NULL be, 78, 85, 76, 76, or just 0 or, 4E, 55, 4C, 4C
can u paste an example of your code.
I was trying it the same way you where doing it. This is what i was trying to compile.
#include <conio.h>
#include <stdio.h>
int main()
{
textcolor(3);
cprintf("\nTHIS TEXT IS RED\n");
textcolor(18);
cprintf("\nI THINK THIS IS FLASHING RED\n");
}
Shouldent NULL be, 78, 85, 76, 76, or just 0 or, 4E, 55, 4C, 4C
hmm not sure works fine for me, umm try to make sure that the directory to your include is set in your c:\autoexec.bat file, if its not then add it in, something like this at the end will do it
set path=%path%;c:\progra~1\tc\include
that way it'll no where to find conio.h, i'm guessing thats not the problem and if it isnt then i dont know whats wrong.
If you are programming a win32 console program then those function will not work. You should use the WINAPI functions.
Current projects:
1) User Interface Development Kit (C++)
2) HTML SDK (C++)
3) Classes (C++)
4) INI Editor (Delphi)
Im programing it in DOS window.
Shouldent NULL be, 78, 85, 76, 76, or just 0 or, 4E, 55, 4C, 4C
heh i use same comiler as you here is something i made to determine colours, it should be helpful.
¿Red Baron?
"Imagination is more important than knowledge"
-Albert Einstein (1879-1955)
Check out my games!
[code] /* dont forget code tags! */ [/code]