49 lines
733 B
C
49 lines
733 B
C
|
#include <stdio.h>
|
||
|
#include <stdarg.h>
|
||
|
#include <string.h>
|
||
|
|
||
|
char* vpf_int(char *dst,int n){
|
||
|
itoa( n, dst, 10 );
|
||
|
return dst + strlen(dst);
|
||
|
};
|
||
|
|
||
|
int sprintf(char *dst,const char* fmt,...){
|
||
|
va_list args;
|
||
|
int n = 0;
|
||
|
|
||
|
va_start( args, fmt );
|
||
|
|
||
|
while (*fmt){
|
||
|
|
||
|
if (*fmt == '%'){
|
||
|
fmt++;
|
||
|
|
||
|
switch (*fmt){
|
||
|
case 'd':
|
||
|
case 'i':
|
||
|
dst = vpf_int( dst, va_arg( args, int ));
|
||
|
break;
|
||
|
case 's':
|
||
|
strcpy( dst, va_arg( args, char* ) );
|
||
|
dst += strlen( dst );
|
||
|
break;
|
||
|
case 'x':
|
||
|
itoa( va_arg( args, int ), dst, 16);
|
||
|
dst += strlen(dst);
|
||
|
break;
|
||
|
case '%':
|
||
|
*(dst++) = '%';
|
||
|
};
|
||
|
|
||
|
} else {
|
||
|
*(dst++) = *fmt;
|
||
|
};
|
||
|
|
||
|
fmt++;
|
||
|
}
|
||
|
|
||
|
*dst = 0x00;
|
||
|
|
||
|
va_end( args );
|
||
|
return n;
|
||
|
};
|