ref: a3d9c8a50f2bd94224725e329b1d2482a7b0718d
dir: /libc/scanf.c/
#include <u.h> #include <libc.h> int scanf (char * str, ...) { va_list vl; int i = 0, j=0, ret = 0; char buff[100] = {0}, tmp[20], c; char *out_loc; while(c != '\0') { c = ps2_getc(); buff[i] = c; i++; } va_start( vl, str ); i = 0; while (str && str[i]) { if (str[i] == '%') { i++; switch (str[i]) { case 'c': { *(char *)va_arg( vl, char* ) = buff[j]; j++; ret ++; break; } case 'd': { *(int *)va_arg( vl, int* ) =strtol(&buff[j], &out_loc, 10); j+=out_loc -&buff[j]; ret++; break; } case 'x': { *(int *)va_arg( vl, int* ) =strtol(&buff[j], &out_loc, 16); j+=out_loc -&buff[j]; ret++; break; } } } else { buff[j] =str[i]; j++; } i++; } va_end(vl); return ret; }