Transferred from: http://www.cnblogs.com/yeahgis/archive/2013/01/22/2872179.html
Windows platform thread safe format string function sprint_s is not a standard C function, so Linux cannot be used, but you can use the snprintf function instead.
/*function Prototypes:*/intsnprintfChar*dest, size_t N,Const Char*fmt, ...);/*function Description: Copy n-1 characters from the source string to the target string, and then add a 0 to the back. So if the size of the target string is n, it will not overflow. function return value: Returns the number of characters stored in the array if successful, and a negative value if an error is encoded. Recommended usage:*/voidFConst Char*p) { Charbuf[ One]={0}; snprintf (BUF,sizeof(BUF),"%10s", p);//Note: This 2nd parameter should be used with sizeof (STR) instead of hard-coded 11 and should not use sizeof (str)-1 orprintf"%SN", buf);}
Substitution of sprintf_s functions under Linux (reproduced)