Here is my code:
Code:
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
main()
{
clrscr();
system("Color F0");
printf("Hello world!");
getch();
return 0;
}
Here is my code:
Code:
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
main()
{
clrscr();
system("Color F0");
printf("Hello world!");
getch();
return 0;
}
Do you have a question hidden somewhere in your post?
In code::blocks when i run it
It runs fine with output having black text in white background
But in turbo c
It shows invalid color command and then shows normal text.
It still the statement - not a question.
So instead of answer - I have 2 comments:
1. system is not a portable solution so while it can work in one environment do not expect it to work in another.
2. turbo C is 25 years old. Use it only if you have somewhere stored a 25 years old computer and plan to run your programs on it. IBM XT maybe.
If it's just colored text then you could use <windows.h> and SetConsoleTextAttribute() with a modern compiler.
See all the color attributes here.Code:#include <stdio.h>
#include <windows.h>
int main(void) {
HANDLE hwnd = GetStdHandle(STD_OUTPUT_HANDLE);
if (hwnd == INVALID_HANDLE_VALUE) {
printf("No handle, no color...\n");
return 0;
}
CONSOLE_SCREEN_BUFFER_INFO hwndInfo;
DWORD oldAttributes;
/* get and save old attributes */
GetConsoleScreenBufferInfo(hwnd, &hwndInfo);
oldAttributes = hwndInfo.wAttributes;
/* You must combine red, blue, and green constants, on the foreground and background to make color.
Leaving out the foreground (as in the example) or the background will make it black. */
SetConsoleTextAttribute(hwnd, BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);
printf("Colored text example in \n");
SetConsoleTextAttribute(hwnd, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
printf("Yellow, ");
SetConsoleTextAttribute(hwnd, FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
printf("cyan, ");
SetConsoleTextAttribute(hwnd, FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
printf("and magenta.\n");
SetConsoleTextAttribute(hwnd, oldAttributes);
printf("Think in 8-bit RGB combinations.\n");
return 0;
}