Internationalization and localization tools


String Format Function

int vsprintf(char *buffer, const char *format, va_list argptr);

int vswprintf(wchar_t *buffer, const wchar_t *format , va_list argptr);

int _vstprintf(TCHAR *buffer, const TCHAR *format, va_list argptr);

Internationalization (I18n) Function Overview

The vsprintf function writes output to buffer under control of the format argument. A null character is placed at the end of the string and the number of single-byte characters written is returned, or -1 if an error occurs.

The vswprintf function is unusual in that the ANSI version and the Windows version of vswprintf are actually different functions. This help page documents the Windows vswprintf function, which is a wide version of vsprintf.

The ANSI vswprintf function on the other hand is more akin to the Windows _vsnwprintf function. If scanning an ANSI code base and investigating the vswprintf function, this is the wrong help page. Please see ANSI vswprintf instead.

_vstprintf is the Windows-only Generic version of the function; with the _MBCS or _UNICODE compiler flags determining its mapping to either vsprintf or vwtprintf.

On Windows platforms, vswprintf is the wide character version of the function and returns the number of wide characters written.

On ANSI platforms, technically speaking there is no wide version of this function. This is because ANSI does support a function called vswprintf, however it acts more like vsnprintf in that it requires a count parameter containing the number of characters that can be printed.

I18n Issues

If scanning an ANSI code base and investigating the vswprintf function, this is the wrong help page. Please see ANSI vswprintf instead.

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_NUMERIC locale category. See String Formatting in C and C++ for a discussion on locale-sensitive formatting in internationalized applications.

There is no ANSI wide character version of this function, per se. You can use the ANSI vswprintf function, but note you will now have to pass an additional count parameter.

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

 

Lingoport internationalization and localization services and software