_cscanf, _cwscanf
Reads formatted data from the console.
int _cscanf( const char *format [, argument] ... ); int _cwscanf( const wchar_t *format [, argument] ... );
Parameters
- format
- Format-control string.
- argument
- 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.
Remarks
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 |
Requirements
| 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.
Libraries
All versions of the C run-time libraries.
Example
// 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" );
}
Input
1 2 3
Output
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