Exportar (0) Imprimir
Expandir todo
div
eof
Expandir Minimizar
Este tema aún no ha recibido ninguna valoración - Valorar este tema

_cscanf_s, _cscanf_s_l, _cwscanf_s, _cwscanf_s_l

Read formatted data from the console. These are more secure versions of _cscanf, _cscanf_l, _cwscanf, _cwscanf_l with security enhancements as described in Security Enhancements in the CRT.


int _cscanf_s( 
   const char *format [,
      argument] ... 
);
int _cscanf_s_l( 
   const char *format,
   locale_t locale [,
      argument] ... 
);
int _cwscanf_s( 
   const wchar_t *format [,
      argument] ... 
);
int _cwscanf_s_l( 
   const wchar_t *format,
   locale_t locale [,
      argument] ... 
);

Parameters

format

Format-control string.

argument

Optional parameters.

locale

The locale to use.

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.

These functions validate their parameters. If format is a null pointer, these functions invoke the invalid parameter handler, as described in Parameter Validation. If execution is allowed to continue, these functions return EOF and errno is set to EINVAL.

The _cscanf_s 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_s function. While _cscanf_s normally echoes the input character, it does not do so if the last call was to _ungetch.

Like other secure versions of functions in the scanf family, _cscanf_s and _cswscanf_s require size arguments for the type field characters c, C, s, S, and [. For more information, see scanf Width Specification.

NoteNote

The size parameter is of type unsigned, not size_t.

The versions of these functions with the _l suffix are identical except that they use the locale parameter passed in instead of the current thread locale.

Generic-Text Routine Mappings
TCHAR.H routine _UNICODE and _MBCS not defined _MBCS defined _UNICODE defined

_tcscanf_s

_cscanf_s

_cscanf_s

_cwscanf_s

_tcscanf_s_l

_cscanf_s_l

_cscanf_s_l

_cwscanf_s_l

Routine Required header Compatibility

_cscanf_s, _cscanf_s_l

<conio.h>

Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003

_cwscanf_s, _cwscanf_s_l

<conio.h> or <wchar.h>

Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003

For more compatibility information, see Compatibility in the Introduction.

All versions of the C run-time libraries.

// crt_cscanf_s.c
// compile with: /c
/* This program prompts for a string
 * and uses _cscanf_s to read in the response.
 * Then _cscanf_s returns the number of items
 * matched, and the program displays that number.
 */

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

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

   result = _cscanf_s( "%i %i %i", &n[0], &n[1], &n[2] );
   _cprintf_s( "\r\nYou entered " );
   for( i=0; i<result; i++ )
      _cprintf_s( "%i ", n[i] );
   _cprintf_s( "\r\n" );
}
1 2 3
You entered 1 2 3
¿Te ha resultado útil?
(Caracteres restantes: 1500)
Gracias por sus comentarios

Adiciones de comunidad

AGREGAR
Mostrar:
© 2014 Microsoft. Reservados todos los derechos.