www.pudn.com > iccavr_lib.rar > csscanf.c, change:2002-06-14,size:997b


#include <stdarg.h> 
#include <_const.h> 
extern void _scanf(char (*)(void), void (*)(char), CONST char *, va_list); 
 
static char *p; 
static char c; 
static char _geti(void) 
	{ 
	char v; 
 
	if (c) 
		{ 
		v = c; 
		c = 0; 
		} 
	else 
		{ 
		v = *p; 
		if (v) 
			p++; 
		} 
	return v; 
	} 
 
static void _ungeti(char v) 
	{ 
	c = v; 
	} 
 
int sscanf(char *buf, CONST char *fmt, ...) 
	{ 
	va_list va; 
 
	c = 0; 
	p = buf; 
	va_start(va, fmt); 
	_scanf(_geti, _ungeti, fmt, va); 
	if (c) 
		--p; 
	va_end(va); 
	return p - buf; 
	} 
 
#if 0 
main() 
	{ 
	int c, i, j; 
 
	c = xsscanf("hello", "hello"); 
	printf("5 is %d\n", c); 
	c = xsscanf("hello 10", "hello %d", &i); 
	printf("8 is %d 10 is %d\n", c, i); 
	c = xsscanf("hello 10 20", "hello %d %u", &i, &j); 
	printf("11 is %d 10 is %d 20 is %d\n", c, i, j); 
	c = xsscanf("hello 10", "hello %x", &i); 
	printf("8 is %d 16 is %d\n", c, i); 
	c = xsscanf("hello 10", "hello %lx", &i); 
	printf("8 is %d 16 is %d\n", c, i); 
	} 
#endif