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 dec
sprintf_s is only part of Annex K, an optional Annex to the C11 standard:
Annex K
...
K.2 Scope
- This annex specifies a series of optional extensions that can be useful in the mitigation of security vulnerabilities in programs, and comprise new functions, macros, and types declared or defined in existing standard headers.
...
K.3.5.3.6 The sprintf_s function
Synopsis
#define __STDC_WANT_LIB_EXT1__1 #includeint sprintf_s(char * restrict s, rsize_t n, const char * restrict format, ...);
(emphasis added)
It never made it into POSIX (or Linux) (and is not missed at all, there are even arguments about its usefulness in the committee).
For better portability, use snprintf which is part of the core standard and provides all the functionality you'll need.