Can I have font color in C(e.g. blue, red, green, etc...)??
If I can... how? thx......
Can I have font color in C(e.g. blue, red, green, etc...)??
If I can... how? thx......
Well......you can modify your config.sys (maybe it's autoexec.bat...i forget)...and load the DOS based ANSI.SYS file....if the ANSI.SYS is loaded, then there are all new kinds of escape codes you can throw in your printf statements which allow to print in colors (foreground and background) and some other neat things..........without loading ANSI.SYS...i don't know...
Well, Your question was a bit ambiguous. Did u want the colours of the C-Editor (TC IDE). I guess no, I think you want to know how to change the colours of the font (foreground and background) for the text that you print using printf etc.
Try this...
Include CONIO.H header file (small case)
then use "textcolor(int)" and "textbackground(int)" functions to set the foreground and background colours respectively and then use the "cprintf()" function just like you used printf().
Regards.
Help everyone you can
Well, Your question was a bit ambiguous. Did u want the colours of the C-Editor (TC IDE). I guess no, I think you want to know how to change the colours of the font (foreground and background) for the text that you print using printf etc.
Try this...
Include CONIO.H header file (small case)
then use "textcolor(int)" and "textbackground(int)" functions to set the foreground and background colours respectively and then use the "cprintf()" function just like you used printf().
Eg:
#include<conio.h>
void main()
{
textbackground(10);
clrscr();
printf("THIS IS WHITE"); /* This is default and always prints in white */
textcolor(8);
cprintf("THIS IS ONE COLOUR");
textcolor(13);
cprintf("THIS IS ANOTHER COLOUR");
} /*This is the manner */
Hope you got my point.
Regards.
Help everyone you can
Sorry... I don't get your point...
Where are those functions from?
textbackground(); clrscr(); textcolor();
I don't understand... would you mind explaining them again.... sorry.... thx....
Free the weed!! Class B to class C is not good enough!!
And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi
thx!!
I found out a good code there... but I don't understand....
Would anyone tell me how it work? thx.....Code:#include <stdio.h> #include <windows.h> int main(){ HANDLE h; h = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleTextAttribute(h, FOREGROUND_RED); printf ("Red font color!\n"); return EXIT_SUCCESS; }
from the good ol helpfiles....
The SetConsoleTextAttribute function sets the foreground (text) and background color attributes of characters written to the screen buffer by the WriteFile or WriteConsole function, or echoed by the ReadFile or ReadConsole function. This function affects only text written after the function call.
BOOL SetConsoleTextAttribute(
HANDLE hConsoleOutput, // handle to console screen buffer
WORD wAttributes // text and background colors
);
Parameters
hConsoleOutput
Handle to a console screen buffer. The handle must have GENERIC_READ access.
wAttributes
Specifies the foreground and background color attributes. Any combination of the following values can be specified: FOREGROUND_BLUE, FOREGROUND_GREEN, FOREGROUND_RED, FOREGROUND_INTENSITY, BACKGROUND_BLUE, BACKGROUND_GREEN, BACKGROUND_RED, and BACKGROUND_INTENSITY. For example, the following combination of values produces white text on a black background:
FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE
Return Values
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
Remarks
To determine the current color attributes of a screen buffer, call the GetConsoleScreenBufferInfo function.
QuickInfo
Windows NT: Requires version 3.1 or later.
Windows: Requires Windows 95 or later.
Windows CE: Unsupported.
Header: Declared in wincon.h.
Import Library: Use kernel32.lib.
and
The GetStdHandle function returns a handle for the standard input, standard output, or standard error device.
HANDLE GetStdHandle(
DWORD nStdHandle // input, output, or error device
);
Parameters
nStdHandle
Specifies the device for which to return the handle. This parameter can have one of the following values: Value Meaning
STD_INPUT_HANDLE Standard input handle
STD_OUTPUT_HANDLE Standard output handle
STD_ERROR_HANDLE Standard error handle
Return Values
If the function succeeds, the return value is a handle to the specified device.
If the function fails, the return value is the INVALID_HANDLE_VALUE flag. To get extended error information, call GetLastError.
Remarks
Handles returned by GetStdHandle can be used by applications that need to read from or write to the console. When a console is created, the standard input handle is a handle to the console's input buffer, and the standard output and standard error handles are handles of the console's active screen buffer. These handles can be used by the ReadFile and WriteFile functions, or by any of the console functions that access the console input buffer or a screen buffer (for example, the ReadConsoleInput, WriteConsole, or GetConsoleScreenBufferInfo functions).
All handles returned by this function have GENERIC_READ and GENERIC_WRITE access unless the SetStdHandle function has been used to set a standard handle to be some handle with a lesser access.
The standard handles of a process may be redirected by a call to SetStdHandle, in which case GetStdHandle returns the redirected handle. If the standard handles have been redirected, you can specify the CONIN$ value in a call to the CreateFile function to get a handle to a console's input buffer. Similarly, you can specify the CONOUT$ value to get a handle to a console's active screen buffer.
QuickInfo
Windows NT: Requires version 3.1 or later.
Windows: Requires Windows 95 or later.
Windows CE: Unsupported.
Header: Declared in winbase.h.
Import Library: Use kernel32.lib.
Free the weed!! Class B to class C is not good enough!!
And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi
vsriharsha, Thank you.
I just spent more than a week scouring books and the net for an answer to this question and your chunk of code worked perfectly.
Glad 2 note that u got what ur looking for.
If you are not using borland then instead of using conio.h use conio.c
Data.