Compartilhar via


_cscanf

Reads formatted data from the console.

**int_cscanf(constchar*format [,**argument] ... );

Routine Required Header Compatibility
_cscanf <conio.h> Win 95, Win NT

For additional compatibility information, see Compatibility in the Introduction.

Libraries

LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version

Return Value

_cscanf 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 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.

Parameters

format

Format-control string

argument

Optional parameters

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.

Example

/* 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" );
}

Output

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

Console and Port I/O Routines

See Also   _cprintf, fscanf, scanf, sscanf