标签:scan ace read pil null assigned sed tsp stream
int __cdecl scanf (
const char *format,
...
)
{
va_list arglist;
va_start(arglist, format);
return vscanf_fn(_input_l, format, NULL, arglist);
}
int __cdecl vscanf_fn (
INPUTFN inputfn,
const char *format,
_locale_t plocinfo,
va_list arglist
)
/*
* stdin 'SCAN', 'F'ormatted
*/
{
int retval = 0;
_VALIDATE_RETURN( (format != NULL), EINVAL, EOF);
_lock_str2(0, stdin);
__try {
retval = (inputfn(stdin, format, plocinfo, arglist));
}
__finally {
_unlock_str2(0, stdin);
}
return(retval);
}
/***
*int _input(stream, format, arglist), static int input(format, arglist)
*
*Purpose:
* get input items (data items or literal matches) from the input stream
* and assign them if appropriate to the items thru the arglist. this
* function is intended for internal library use only, not for the user
*
* The _input entry point is for the normal scanf() functions
* The input entry point is used when compiling for _cscanf() [CPRFLAF
* defined] and is a static function called only by _cscanf() -- reads from
* console.
*
* This code also defines _input_s, which works differently for %c, %s & %[.
* For these, _input_s first picks up the next argument from the variable
* argument list & uses it as the maximum size of the character array pointed
* to by the next argument in the list.
*
*Entry:
* FILE *stream - file to read from
* char *format - format string to determine the data to read
* arglist - list of pointer to data items
*
*Exit:
* returns number of items assigned and fills in data items
* returns EOF if error or EOF found on stream before 1st data item matched
*
*Exceptions:
*
*******************************************************************************/
static _TINT __cdecl _inc(FILE* fileptr)
{
return (_gettc_nolock(fileptr));
}
static void __cdecl _un_inc(_TINT chr, FILE* fileptr)
{
if (_TEOF != chr) {
_ungettc_nolock(chr,fileptr);
}
}
static _TINT __cdecl _whiteout(int* counter, FILE* fileptr)
{
_TINT ch;
do
{
++*counter;
ch = _inc(fileptr);
if (ch == _TEOF)
{
break;
}
}
while(_istspace((_TUCHAR)ch));
return ch;
}
while (*format) {
if (_istspace((_TUCHAR)*format)) {
UN_INC(EAT_WHITE()); /* put first non-space char back */
do {
tch = *++format;
} while (_istspace((_TUCHAR)tch));
continue;
………………
if (_T('%') == *format && _T('%') != *(format + 1))
if (_T('^') == *scanptr) {
++scanptr;
--reject; /* set reject to 255 */
}
/* Allocate "table" on first %[] spec */
#if ALLOC_TABLE
if (table == NULL) {
table = (char*)_malloc_crt(TABLESIZE);
if ( table == NULL)
goto error_return;
malloc_flag = 1;
}zuolizi
#endif /* ALLOC_TABLE */
memset(table, 0, TABLESIZE);
if (LEFT_BRACKET == comchr)
if (_T(']') == *scanptr) {
prevchar = _T(']');
++scanptr;
table[ _T(']') >> 3] = 1 << (_T(']') & 7);
}
while (_T(']') != *scanptr) {
rngch = *scanptr++;
if (_T('-') != rngch ||
!prevchar || /* first char */
_T(']') == *scanptr) /* last char */
table[(prevchar = rngch) >> 3] |= 1 << (rngch & 7);
else { /* handle a-z type set */
rngch = *scanptr++; /* get end of range */
if (prevchar < rngch) /* %[a-z] */
last = rngch;
else { /* %[z-a] */
last = prevchar;
prevchar = rngch;
}
/* last could be 0xFF, so we handle it at the end of the for loop */
for (rngch = prevchar; rngch < last; ++rngch)
{
table[rngch >> 3] |= 1 << (rngch & 7);
}
table[last >> 3] |= 1 << (last & 7);
prevchar = 0;
}
}
table[rngch >> 3] |= 1 << (rngch & 7);
(table[ch >> 3] ^ reject) & (1 << (ch & 7))
if (_T('%') == *format && _T('%') != *(format + 1)) {
……………………
++format; /* skip to next char */
} else /* ('%' != *format) */
{
………………………
}
static _TINT __cdecl _hextodec ( _TCHAR chr)
{
return _ISDIGIT(chr) ? chr : (chr & ~(_T('a') - _T('A'))) - _T('A') + 10 + _T('0');
}
#include<cstdio>
#include<cstdarg>
int my_scanf(char* fmt,...)
{
int ret=0;
va_list args;
va_start(args,fmt);
vscanf(fmt,args);
va_end(args);
return ret;
}
int main()
{
int a;
my_scanf("%d",&a);
printf("%d",a);
return 0;
}
标签:scan ace read pil null assigned sed tsp stream
原文地址:https://www.cnblogs.com/Syameimaru/p/10109729.html