Hello. I'm using ncurses with a side project I'm working on, and I'm using colored characters. To use colors, you have to wrap each mvprintw() function with some code to set the color. I thought I'd write a function that wraps mvprintw() so I could just specify the color whenever I print something.
Here's what I've got:
void mvprintw_color(int y, int x, int color, char* fmt, ...)
{
/* This is for the variable length arguments */
va_list args;
va_start(args, fmt);
if (has_colors() == TRUE)
{
/* If colors are supported, set the fg and bg colors */
attron(COLOR_PAIR(color));
mvprintw(y, x, fmt, args);
/* Turn off the coloring */
attroff(COLOR_PAIR(color));
}
else
{
mvprintw(y, x, fmt, args);
}
/* Variable length arguments macro*/
va_end(args);
}
When I test it, I get random characters instead of what I want to print, but it is the correct color. It seems like I've messed up something with the variable length arguments stuff, but I looked at example functions on several websites and I did it similar to them.
Any idea what's going wrong here?