1.Cè¯è¨ printfåscanfçå®ç°
Cè¯è¨ printfåscanfçå®ç°
/* Write formatted output to stdout from the format string FORMAT. */
/* VARARGS1 */
int
__printf (const char *format,源码多线程启动源码 ...)
{
va_list arg;
int done;
va_start (arg, format);
done = vfprintf (stdout, format, arg);
va_end (arg);
return done;
}
int _scanf(char (*get)(void), void (*unget)(char), CONST char *fmt, va_list va)
{
int is_long, c, base;
char *vp;
char s[MAX+1];
int converted = 0;
while (c = *fmt++)
{
if (c == '%')
{
if (*fmt == 'l')
{
is_long = 1;
fmt++;
}
else
is_long = 0;
vp = va_arg(va, void *);
switch (*fmt)
{
case 'c':
*(char *)vp = get();
converted++;
break;
case 'o': base = 8; goto read_strtoul;
case 'u': base = ; goto read_strtoul;
case 'X':
case 'x': base = ;
read_strtoul:
converted++;
ReadInteger(s, get, unget, base);
if (is_long)
*(unsigned long *)vp = strtoul(s, 0, base);
else
*(unsigned *)vp = strtoul(s, 0, base);
break;
case 'd':
converted++;
ReadInteger(s, get, unget, );
if (is_long)
*(long *)vp = strtol(s, 0, );
else
*(int *)vp = strtol(s, 0, );
break;
case 's':
converted++;
ReadString(vp, get, unget);
break;
default:
puts("unsupported format");
break;
}
fmt++;
}
else if (isspace(c))
{
while ((c = get()) && isspace(c))
;
unget(c);
}
else if (get() != c)
break;
}
return converted;
}