Export (0) Print
Expand All
div
eof
Expand Minimize

_cprintf, _cprintf_l, _cwprintf, _cwprintf_l 

Formats and prints to the console. More secure versions are available; see _cprintf_s, _cprintf_s_l, _cwprintf_s, _cwprintf_s_l.


int _cprintf( 
   const char * format [, 
      argument] ... 
);
int _cprintf_l( 
   const char * format,
   locale_t locale [,
      argument] … 
);
int _cwprintf(
   const wchar * format [, 
      argument] …
);
int _cwprintf_l(
   const wchar * format,
   locale_t locale [, 
      argument] …
);

Parameters

format

Format-control string.

argument

Optional parameters.

locale

The locale to use.

The number of characters printed.

These functions format and print a series of characters and values directly to the console, using the _putch function (_putwch for _cwprintf) 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 function. Unlike the fprintf, printf, and sprintf functions, neither _cprintf nor _cwprintf translates line-feed characters into carriage return–line feed (CR-LF) combinations when output.

An important distinction is that _cwprintf displays Unicode characters when used in Windows NT. Unlike _cprintf, _cwprintf 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.

_cprintf validates the format parameter. If format is a null pointer, the function invokes the invalid parameter handler, as described in Parameter Validation. If execution is allowed to continue, the function returns -1 and sets errno to EINVAL.

Security noteSecurity Note

Ensure that format is not a user-defined string.

Generic-Text Routine Mappings
Tchar.h routine _UNICODE and _MBCS not defined _MBCS defined _UNICODE defined

_tcprintf

_cprintf

_cprintf

_cwprintf

_tcprintf_l

_cprintf_l

_cprintf_l

_cwprintf_l

Routine Required header Compatibility

_cprintf, _cprintf_l

<conio.h>

Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003

_cwprintf, _cwprintf_l

<conio.h>

Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003

For more compatibility information, see Compatibility in the Introduction.

// crt_cprintf.c
// compile with: /c
// This program displays some variables to the console.

#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( "%d  %.4x  %u  %c %s\r\n", i, h, u, c, s );
}

Sample Output

-16  001d  62511  A Test

Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.

Community Additions

ADD
Show:
© 2014 Microsoft