A better macro to concat 2 strings with __COUNTER__

In C I am trying write a macro that will append __COUNTER__ to the end of a filename (before the file type). I have tried several things, and the only thing I could get to work the way I wanted was this:

1
2
char FILENAME__[20];
#define MAKE_FIGURE(IMG) sprintf(FILENAME__,"Images/Figure%03d.jpg",__COUNTER__);  cvSaveImage(FILENAME__,IMG);  


Any suggestions?
Why not just write a function.

PS: Names with double underscores in them are reserved in C++, and I wouldn't be surprised if that would apply for C too.
Names with double underscores in them are reserved in C++
No, they're not. It's just that, by convention, internal identifiers begin with one or more underscores to prevent collision with user symbols. It would be absurd that no symbol with two successive underscores anywhere could be used. Like _____________ or __________________________.
Regardless, not every identifier will be taken. 17.4.3.2.1 is merely a formalism. Most compilers don't even check for it.
Topic archived. No new replies allowed.