Reads formatted data from the console.
#include <conio.h> | Required only for function declarations |
int _cscanf( char *format [[, argument]] ...);
format | Format-control string | |
argument | Optional arguments |
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 argument 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 argument for the scanf function; see scanf for a description of format.
While _cscanf normally echoes the input character, it will not do so if the last call was to _ungetch.
The _cscanf function returns 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 may occur when keyboard input is redirected at the operating system command-line level. A return value of 0 means that no fields were assigned.
Standards:None
16-Bit:DOS, QWIN, WIN, WIN DLL
32-Bit:DOS32X
_cprintf, fscanf, scanf, sscanf
/* CSCANF.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>
void 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" );
}
Enter three integers: 34 43 987k
You entered 987 43 34