aboutsummaryrefslogtreecommitdiff
path: root/printf.c
blob: b34ade1b47b1e1a03ef5bd669c0c259161262833 (plain) (blame)
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
int printf(char *fmt, int pos) {
    char *arg, ch;
    int len, x;
    arg = (int)&pos;
    while ((ch = *fmt))
    {
        if (ch == '%')
        {
            ch = *(++fmt);
            if (ch == 'd')
                __print_int(*(int *)arg);
            else if (ch == 'c')
                __print_char(*(char *)arg);
            else if (ch == 's')
                __print_string(*(char **)arg);
            else
            {
                x = *(int *)arg;
                if (!x) len = 1;
                else
                    for (len = 0; x; x /= 10, len++);
                len = 4 - len;
                while (len) __print_char('0'), len--;
                __print_int(*(int *)arg);
                fmt += 2;
            }
            arg += 4;
        }
        else __print_char(ch);
        fmt++;
    }
}