From 952c5c128f9efaea89d41d882c4ea3ade7df4591 Mon Sep 17 00:00:00 2001 From: zakk Date: Fri, 26 Aug 2005 04:48:05 +0000 Subject: Itsa me, quake3io! git-svn-id: svn://svn.icculus.org/quake3/trunk@2 edf5b092-35ff-0310-97b2-ce42778d08ea --- lcc/tst/stdarg.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100755 lcc/tst/stdarg.c (limited to 'lcc/tst/stdarg.c') diff --git a/lcc/tst/stdarg.c b/lcc/tst/stdarg.c new file mode 100755 index 0000000..ff6c918 --- /dev/null +++ b/lcc/tst/stdarg.c @@ -0,0 +1,51 @@ +#include + +struct node { int a[4]; } x = {1,2,3,4}; + +print(char *fmt, ...); + +main() { + print("test 1\n"); + print("test %s\n", "2"); + print("test %d%c", 3, '\n'); + print("%s%s %w%c", "te", "st", 4, '\n'); + print("%s%s %f%c", "te", "st", 5.0, '\n'); + print("%b %b %b %b %b %b\n", x, x, x, x, x, x); + return 0; +} + +print(char *fmt, ...) { + va_list ap; + + va_start(ap, fmt); + for (; *fmt; fmt++) + if (*fmt == '%') + switch (*++fmt) { + case 'b': { + struct node x = va_arg(ap, struct node); + printf("{%d %d %d %d}", x.a[0], x.a[1], x.a[2], x.a[3]); + break; + } + case 'c': + printf("%c", va_arg(ap, char)); + break; + case 'd': + printf("%d", va_arg(ap, int)); + break; + case 'w': + printf("%x", va_arg(ap, short)); + break; + case 's': + printf("%s", va_arg(ap, char *)); + break; + case 'f': + printf("%f", va_arg(ap, double)); + break; + default: + printf("%c", *fmt); + break; + } + else + printf("%c", *fmt); + va_end(ap); +} -- cgit v1.2.3