I have a C program that uses sprintf_s
. It works fine in Windows, but when I compile my code in Linux it gives this error:
sprintf_s was not declared in this scope.
Why does this happen and how can I fix it?
The sprintf_s is defined in the stdio. h header file and is the security-enhanced alternate of the sprintf function. It uses a format string and corresponding arguments to generate a string that stores in the provided destination string.
Printf() is defined in the stdio. h and implemented in the libc library. Older versions of C did not require a declaration before calling a function.
One main difference between sprintf_s and sprintf is that sprintf_s checks the format string for valid formatting characters, whereas sprintf only checks if the format string or buffer are NULL pointers.
It's not standard, you won't find such function on Linux.
Standard function snprintf
should have a similar semantics.
sprintf_s is not part of the standard C library, so it is not portable, thus you are not able to use it in Linux. BUT you have snprintf, which is very similar and it should help you to accomplish what you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With