_printf_p, _printf_p_l, _wprintf_p, _wprintf_p_l

Prints formatted output to the standard output stream, with the ability to specify the order in which parameters are used in the format string.

int _printf_p(
   const char *format [,
int _printf_p_l(
   const char *format,
   locale_t locale [,
int _wprintf_p(
   const wchar_t *format [,
int _wprintf_p_l(
   const wchar_t *format,
   locale_t locale [,


Format control.


Optional arguments.


The locale to use.

Returns the number of characters printed or a negative value if an error occurs.

The _printf_p function formats and prints a series of characters and values to the standard output stream, stdout. If arguments follow the format string, the format string must contain specifications that determine the output format for the arguments (see printf_p Positional Parameters).

The difference between _printf_p and printf_s is that _printf_p supports positional parameters, which allows specifying the order in which the arguments are used in the format string. For more information, see printf_p Positional Parameters.

_wprintf_p is the wide-character version of _printf_p; they behave identically if the stream is opened in ANSI mode. _printf_p doesn't currently support output into a UNICODE stream.

The versions of these functions with the _l suffix are identical except that they use the locale parameter passed in instead of the current thread locale.

Security noteSecurity Note

Ensure that format is not a user-defined string.

If format or argument are NULL, or of the format string contains invalid formatting characters, _printf_p and _wprintf_p functions invoke an invalid parameter handler, as described in Parameter Validation. If execution is allowed to continue, the function returns -1 and sets errno to EINVAL.

Generic-Text Routine Mappings

Tchar.h routine

_UNICODE and _MBCS not defined

_MBCS defined

_UNICODE defined










Required header

_printf_p, _printf_p_l


_wprintf_p, _wprintf_p_l

<stdio.h> or <wchar.h>

For more compatibility information, see Compatibility in the Introduction.

// crt_printf_p.c
// This program uses the _printf_p and _wprintf_p
// functions to choose the order in which parameters
// are used.

#include <stdio.h>

int main( void )
   // Positional arguments 
   _printf_p( "Specifying the order: %2$s %3$s %1$s %4$s %5$s.\n",
              "little", "I'm", "a", "tea", "pot");

   // Resume arguments
   _wprintf_p( L"Reusing arguments: %1$d %1$d %1$d %1$d\n", 10);

   // Width argument
   _printf_p("Width specifiers: %1$*2$s", "Hello\n", 10);
Specifying the order: I'm a little tea pot.
Reusing arguments: 10 10 10 10
Width specifiers:     Hello

Community Additions