| String Format Function int snprintf(char *buffer, size_t count, const char *format [, argument] ...);  int _snprintf(char *buffer, size_t count, const char *format [, argument] ...);  int swprintf(wchar_t *buffer, size_t count, const wchar_t *format [, argument] ...  int _snwprintf(wchar_t *buffer, size_t count, const wchar_t *format [, argument] ...);  int _sntprintf(TCHAR *buffer, size_t count, const TCHAR *format [, argument] ...); Internationalization (I18n) Function OverviewThe _snprintf/snprintffunction formats and stores a maximum ofcountcharacters inbuffer, under the control offormatand its optionalargumentdata. The swprintffunction is unusual in that the ANSI version and the Windows version ofswprintfare actually different functions.  This help page documents the ANSIswprintffunction, which is akin to the Windows_snwprintffunction. The Windows swprintffunction on the hand is a wide version ofsprintf.
If scanning a Windows code base and investigating theswprintffunction, this is the wrong help page.  Please see Windowsswprintfinstead. On Windows platforms, the _snprintffunction returns the number of bytes written. On error a negative value is returned. On ANSI platforms, the snprintffunction returns the number of characters written.  Prior to GNU C Library 2.1, on error a negative value was returned. For GNU C Library 2.1 and later, the error return of thesnprintffunction was changed to be compliant with ISO C99 standards. Instead of a negative value return whencountis too small,snprintfreturns the number of bytes needed for a successful operation, excluding the null-terminating byte. It is up to the caller to check that this value is larger than the space allocated, allowing the function to be called again with a sufficient amount of storage space inbuffer. The Windows _snwprintffunction and ANSIswprintffunction are the wide character versions of_snprintf/snprintf; their parameters are wide-character strings, and they return the number of wide characters written if successful. On error a negative value is returned. _sntprintfis the Windows-only Generic version of the function; with the _MBCS or _UNICODE compiler flags determining its mapping to eithersnprintfor_snwprintf.
 I18n IssuesIf scanning a Windows code base and investigating the swprintffunction, this is the wrong help page.  Please see Windowsswprintfinstead. Use the appropriate version of the function as required for internationalization support, noting the following: Prior to calling one of these functions, ensure that the current locale is set properly by calling setlocale, as string formatting is dependent on the LC_NUMERIClocale category.
See String Formatting in C and C++ for a discussion on locale-sensitive formatting in internationalized applications. Special care must be taken with the countparameter. See Locale-Sensitive Length Functions for a complete discussion of the issues involved with functions that pass length parameters. Recommended Replacements*On Windows platforms, a more secure string function should be used.
These are shown as the first choices in the following table:  
*If you're already using the recommended function, see I18n Issues for other reasons why Globalyzer is detecting the function. String Format Functions    
 |