AppleAssassin
AppleAssassin

Reputation: 493

Adding Colour To Text In C With Bloodshed

Is this possible?

I know it's possible in the command prompt using COLOR ##

but is it possible in C using bloodshed?

Thanks,

Upvotes: 1

Views: 300

Answers (2)

wholerabbit
wholerabbit

Reputation: 11566

If you're on *nix, osx, or using cygwin msys on windows, your terminal should support the ANSI sequences Fred Larson mentions (not sure about osx). The normal windows terminal does not. But bloodshed can use cygwin, so you're in luck.

Here's an example:

#include <stdio.h>

#define BOLDMAGENTA "\033[1;35m"
#define BOLDGREEN "\033[1;32m"

int main(void) {
    printf("%shello %sworld\n", BOLDMAGENTA, BOLDGREEN);
    return 0;
}

Note that this leaves the terminal in bright green, but if your prompt sets colours, that will get reset.

Here's some explanation of ANSI escape codes: http://en.wikipedia.org/wiki/ANSI_escape_code

Upvotes: 1

Shahbaz
Shahbaz

Reputation: 47563

What operating system? What terminal do you have available? Note that this has nothing to do with C, let alone bloodshed. You output a string which the terminal may or may not choose to interpret as a color. You have to see how to do that with your terminal. The solution of course is not portable. One such example for a terminal supporting escape sequences is

printf("\\x1b[1;33mThis is yellow\\x1b[m(Back to default)\n");

You may be interested in ANSI terminal's color escape sequences

You may also want to look for libraries that do that for limited number of terminals. For example, ncurses could help you in Linux.

Upvotes: 2

Related Questions