Code: Select all
typedef uint8t *va_list;
#define va_start(ap, v) ((void) (ap = (va_list) &v + sizeof(v)))
#define va_arg(ap, type) (*((type *)(ap))++)
#define va_end(ap) ((void) (ap = 0))
Code: Select all
void printf(char *format, ...) {
va_list argptr;
char s[34], c, *str;
int num;
va_start(argptr,format);
while(*format != '\0') {
if(*format != '%') {
putchar(*format);
} else {
*format++;
switch(*format) {
case '%':
putchar('%');
break;
case 'b':
num= va_arg(argptr,int);
itoa(s,num,2,PRINTF_SMALL);
printf(s);
break;
case 'c':
c= va_arg(argptr,char);
putchar(c);
break;
case 's':
str= va_arg(argptr,char *);
printf(str);
break;
case 'x':
num= va_arg(argptr,int);
itoa(s,num,16,PRINTF_SMALL);
printf(s);
break;
case 'X':
num= va_arg(argptr,int);
itoa(s,num,16,PRINTF_BIG);
printf(s);
break;
case 'd':
num= va_arg(argptr,int);
itoa(s,num,10,PRINTF_SMALL);
printf(s);
break;
default:
putchar(--*format);
putchar(++*format);
break;
}
}
*format++;
}
va_end(argptr);
}