_cprintf_p, _cprintf_p_l, _cwprintf_p, _cwprintf_p_l
Collapse the table of content
Expand the table of content

_cprintf_p, _cprintf_p_l, _cwprintf_p, _cwprintf_p_l


Formats and prints to the console, and supports positional parameters in the format string.


This API cannot be used in applications that execute in the Windows Runtime. For more information, see CRT functions not supported with /ZW.

int _cprintf_p( 
   const char * format [, 
   argument] ... 
int _cprintf_p_l( 
   const char * format,
   locale_t locale [, 
   argument] ... 
int _cwprintf_p(
   const wchar * format [, 
   argument] ...
int _cwprintf_p_l(
   const wchar * format,
   locale_t locale [,
   argument] ...


Format-control string.


Optional parameters.


The locale to use.

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

These functions format and print a series of characters and values directly to the console, using the _putch and _putwch functions to output characters. Each argument (if any) is converted and output according to the corresponding format specification in format. The format has the same form and function as the format parameter for the printf_p function. The difference between _cprintf_p and cprintf_s is that _cprintf_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.

Unlike the fprintf_p, printf_p, and sprintf_p functions, neither _cprintf_p nor _cwprintf_p translates line-feed characters into carriage return–line feed (CR-LF) combinations when output. An important distinction is that _cwprintf_p displays Unicode characters when used in Windows NT. Unlike _cprintf_p, _cwprintf_p uses the current console locale settings.

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

System_CAPS_security Security Note

Ensure that format is not a user-defined string.

Also, like _cprintf_s and _cwprintf_s, they validate the input pointer and the format string. If format or argument are NULL, or of the format string contains invalid formatting characters, these functions invoke the invalid parameter handler, as described in Parameter Validation. If execution is allowed to continue, these functions return -1 and set errno to EINVAL.

Generic-Text Routine Mappings

Tchar.h routine

_UNICODE and _MBCS not defined

_MBCS defined

_UNICODE defined











Required header





For more compatibility information, see Compatibility.

// crt_cprintf_p.c
// This program displays some variables to the console
// using the _cprintf_p function.

#include <conio.h>

int main( void )
    int         i = -16,
                h = 29;
    unsigned    u = 62511;
    char        c = 'A';
    char        s[] = "Test";

    // Note that console output does not translate
    // \n as standard output does. Use \r\n instead.
    _cprintf_p( "%2$d  %1$.4x  %3$u  %4$c %5$s\r\n", 
                h, i, u, c, s );
-16  001d  62511  A Test
© 2015 Microsoft