_cscanf, _cwscanf
Collapse the table of content
Expand the table of content
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

_cscanf, _cwscanf

Reads formatted data from the console.

int _cscanf( 
   const char *format [,
   argument] ... 
int _cwscanf( 
   const wchar_t *format [,
   argument] ... 


Format-control string.
Optional parameters.

Return Value

The number of fields that were successfully converted and assigned. The return value does not include fields that were read but not assigned. The return value is EOF for an attempt to read at end of file. This can occur when keyboard input is redirected at the operating-system command-line level. A return value of 0 means that no fields were assigned.


The _cscanf function reads data directly from the console into the locations given by argument. The _getche function is used to read characters. Each optional parameter must be a pointer to a variable with a type that corresponds to a type specifier in format. The format controls the interpretation of the input fields and has the same form and function as the format parameter for the scanf function. While _cscanf normally echoes the input character, it does not do so if the last call was to _ungetch.

Generic-Text Routine Mappings

TCHAR.H routine _UNICODE & _MBCS not defined _MBCS defined _UNICODE defined
_tcscanf _cscanf _cscanf _cwscanf


Routine Required header Compatibility
_cscanf <conio.h> Win 98, Win Me, Win NT, Win 2000, Win XP
_cwscanf <conio.h> or <wchar.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_cscanf.c
// compile with: /c
/* This program prompts for a string
 * and uses _cscanf to read in the response.
 * Then _cscanf returns the number of items
 * matched, and the program displays that number.

#include <stdio.h>
#include <conio.h>

int main( void )
   int   result, i[3];

   _cprintf( "Enter three integers: ");
   result = _cscanf( "%i %i %i", &i[0], &i[1], &i[2] );
   _cprintf( "\r\nYou entered " );
   while( result-- )
      _cprintf( "%i ", i[result] );
   _cprintf( "\r\n" );


1 2 3


Enter three integers: 1 2 3
You entered 3 2 1

See Also

Console and Port I/O Routines | _cprintf | fscanf | scanf | sscanf | Run-Time Routines and .NET Framework Equivalents

© 2015 Microsoft