I am unable to use cprintf (color print) in codeblocks . I have used :
textcolor(GREEN);
cprintf("anything");
but compiler is showing problem.Can anyone please help
Color in programme
Moderators:Labib, bristy1588
Re: Color in programme
Show the full code please...
Last edited by *Mahi* on Mon Mar 26, 2012 11:42 am, edited 1 time in total.
Reason: Corrected capitalization
Reason: Corrected capitalization
A man is not finished when he's defeated, he's finished when he quits.
Re: Color in programme
#include<stdio.h>
int main()
{
textcolor(GREEN);
cprintf("anything");
getch();
}
int main()
{
textcolor(GREEN);
cprintf("anything");
getch();
}
Re: Color in programme
In dos environment, your code is right. But in a windows machine, you have to handle things differently. This is an example-
Code: Select all
#include <stdio.h>
#include <windows.h>
int main ( void )
{
HANDLE h = GetStdHandle ( STD_OUTPUT_HANDLE );
WORD wOldColorAttrs;
CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
/*
* First save the current color information
*/
GetConsoleScreenBufferInfo(h, &csbiInfo);
wOldColorAttrs = csbiInfo.wAttributes;
/*
* Set the new color information
*/
SetConsoleTextAttribute ( h, FOREGROUND_RED | FOREGROUND_INTENSITY );
printf ( "This is a test\n" );
/*
* Restore the original colors
*/
SetConsoleTextAttribute ( h, wOldColorAttrs);
return 0;
}
Please read Forum Guide and Rules before you post.
Use $L^AT_EX$, It makes our work a lot easier!
Nur Muhammad Shafiullah | Mahi
Use $L^AT_EX$, It makes our work a lot easier!
Nur Muhammad Shafiullah | Mahi