#include
#include
void minprintf(char *fmt, ...)
{
va_list ap;
int ival;
char *p,*sval;
double dval;
va_start(ap, fmt);
for (p = fmt; *p; ++p)
{
if (*p != '%')
{
putchar (*p);
continue;
}
switch (*++p)
{
case 'd':
ival = va_arg(ap, int);
fprintf (stdout, "%d\t", ival);
break;
case 'f':
dval = va_arg(ap, double);
fprintf (stdout, "%f\t", dval);
break;
case 's':
for (sval = va_arg(ap, char *); *sval; ++sval)
putchar (*sval);
putchar ('\t');
break;
default:
putchar (*p);
break;
}
}
va_end(ap);
}
int main()
{
int i = 10;
double d = 3.1415;
char s[] = "Hello, World!";
minprintf ("%d\n", i);
minprintf ("%d\n", d);
minprintf ("%s\n", s);
return 0;
}
阅读(944) | 评论(0) | 转发(0) |