OpenCores
URL https://opencores.org/ocsvn/eco32/eco32/trunk

Subversion Repositories eco32

[/] [eco32/] [trunk/] [lcc/] [tst/] [stdarg.c] - Blame information for rev 82

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 hellwig
#include <stdarg.h>
2
 
3
struct node { int a[4]; } x = {1,2,3,4};
4
 
5
print(char *fmt, ...);
6
 
7
main() {
8
        print("test 1\n");
9
        print("test %s\n", "2");
10
        print("test %d%c", 3, '\n');
11
        print("%s%s %w%c", "te", "st", 4, '\n');
12
        print("%s%s %f%c", "te", "st", 5.0, '\n');
13
        print("%b %b %b %b %b %b\n", x, x, x, x, x, x);
14
        return 0;
15
}
16
 
17
print(char *fmt, ...) {
18
        va_list ap;
19
 
20
        va_start(ap, fmt);
21
        for (; *fmt; fmt++)
22
                if (*fmt == '%')
23
                        switch (*++fmt) {
24
                        case 'b': {
25
                                struct node x = va_arg(ap, struct node);
26
                                printf("{%d %d %d %d}", x.a[0], x.a[1], x.a[2], x.a[3]);
27
                                break;
28
                                }
29
                        case 'c':
30
                                printf("%c", va_arg(ap, char));
31
                                break;
32
                        case 'd':
33
                                printf("%d", va_arg(ap, int));
34
                                break;
35
                        case 'w':
36
                                printf("%x", va_arg(ap, short));
37
                                break;
38
                        case 's':
39
                                printf("%s", va_arg(ap, char *));
40
                                break;
41
                        case 'f':
42
                                printf("%f", va_arg(ap, double));
43
                                break;
44
                        default:
45
                                printf("%c", *fmt);
46
                                break;
47
                        }
48
                 else
49
                        printf("%c", *fmt);
50
        va_end(ap);
51
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.