-
sprintf_s in unix?
Hi all
I have a very large program I want to run in my unix computer (Mac) and Windows at the same time.
so I have defined:
Code:
#ifndef WIN32
void sprintf_s(char *buffer, size_t sizeOfBuffer, const char *format, ...) {
sprintf(buffer, format, ...); //ERROR: expected primary-expression before '...' token
}
#endif
How can I solve this error?
I use to have
Code:
#define sprintf_s(buffer, buffer_size, stringbuffer, number) (sprintf(buffer, stringbuffer, number))
but it does not work with any number of arguments as the real sprintf_s
Help is appreciated, thanks
Ignacio
-
sprintf_s is not part of the standard C library so is not portable.
However, snprintf is, and you should be able to accomplish what you want with that. It's nearly identical, I think.
-
Thanks MK27, I completely forgot about snprintf().
-
AFAIK, it does not work correctly in MSVC. The return value etc.
-
GCC supports vararg macros.
Code:
#define sprintf_s(buffer, buffer_size, stringbuffer, ...) (sprintf(buffer, stringbuffer, __VA_ARGS__))
Not 100% sure about the syntax.
BTW, VC++2005+ does too.