Problem with multiple definitions

I am using ANSI escape codes in my semi-graphical
program...
my problem is this i have
1
2
#define RED "\033[7;31m"
#define GREEN "\033[1;32m" 

no problems with this...
later in my program i have this
1
2
3
printf(RED);
printf(GREEN);
printf(msg);

msg is something like "hello world"
the problem with the above is that
it will print red bg with black txt or
white on black
i have also tried
1
2
3
4
5
6
7
char message[50];
message[0]='\n';
//requires string.h
strcat(message, GREEN);
strcat(message, RED);
strcat(message,msg);
printf(message);

does the same thing as the other one
I cannot declare them in one line e.g.
 
printf(RED GREEN "%s", msg);

im using hundreds of escape codes so itd take me months...
 
if (background==red && text==green && bold==none)

one of these plus the printf line about 400 times so
what should be a 250-300 line program becomes 1000
1
2
3
4
5
if (noone==canHelp)
{
	//begin 1000 lines...
	code(1000);
}
I could have sworn we helped you here:
http://www.cplusplus.com/forum/beginner/109220/2/

To answer your last question, don't add characters between your formatters. Is there anything wrong when you use andywestken's code snippet?

As for your code block with strcat()... The problem comes from you not putting a null-terminating character ('\0') anywhere in your array. The standard C functions for strings like strcat depend on the array already having one.
So, if you also want the newline:
2
3
message[0] = '\n';
message[1] = '\0';


That special character tells strcat() and many other functions when the string ends, like writing a period after each sentence.
hey i'm sorry when i saw it the first time i thought
he was just showing me how to use variables in #define when i read it again i see
thanks
Topic archived. No new replies allowed.