-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathminprintf.c
More file actions
35 lines (33 loc) · 788 Bytes
/
Copy pathminprintf.c
File metadata and controls
35 lines (33 loc) · 788 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
#include <stdio.h>
#include <stdarg.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':
dval = va_arg(ap, double);
printf("%f", dval);
break;
case 's':
for (sval = va_arg(ap, char *); *sval; sval++)
putchar(sval);
break;
default:
putchar(*p);
break;
}
}
va_end(ap);
}