-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathminprintf.c
More file actions
42 lines (40 loc) · 819 Bytes
/
Copy pathminprintf.c
File metadata and controls
42 lines (40 loc) · 819 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <stdarg.h>
#include <stdio.h>
void minprintf(char *fmt,...)
{
va_list ap;
char *p,*sval;
int ival;
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);
printf("%d",ival);
break;
case 'f':
ival=va_arg(ap,double);
printf("%f",ival);
break;
case 's':
for(sval=va_arg(ap,char *);*sval;sval++)
putchar(*sval);
break;
default:
putchar(*p);
break;
}
}
}
void main()
{
minprintf("%d\n",12);
}