This documentation is archived and is not being maintained.

_cprintf, _cwprintf

Formats and prints to the console.

int _cprintf( 
   const char * format [, 
   argument] ... 
int _cwprintf(
   const wchar * format [, 
   argument] ...


Format-control string.
Optional parameters.

Return Value

_cprintf and _cwprintf return the number of characters printed.


The _cprintf and _cwprintf functions format and print a series of characters and values directly to the console, using the _putch and _putwch functions, respectively, 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.

Security Note   Ensure that format is not a user-defined string.

Generic-Text Routine Mappings

TCHAR.H routine _UNICODE & _MBCS not defined _MBCS defined _UNICODE defined
_tcprintf _cprintf _cprintf _cwprintf


Routine Required header Compatibility
_cprintf <conio.h> Win 98, Win Me, Win NT, Win 2000, Win XP
_cwprintf <conio.h> Win 98, Win Me, Win NT, Win 2000, Win XP

For additional compatibility information, see Compatibility in the Introduction.


All versions of the C run-time libraries.


// 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 );


-16  001d  62511  A Test

See Also

Console and Port I/O Routines | _cscanf | fprintf | printf | sprintf | vfprintf | Run-Time Routines and .NET Framework Equivalents