varargs.c
changeset 0 af501b0c1716
child 9 c3fecc82ade6
new file mode 100644
--- /dev/null
+++ b/varargs.c
@@ -0,0 +1,57 @@
+/*
+ *     $Id: varargs.c,v 1.1.1.1 2008-04-28 17:32:53 mbroeker Exp $
+ * $Source: /development/c/demos/varargs.c,v $
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+
+int params (char *fmt, ...)
+{
+    int i = 0;
+    va_list list;
+    char c;
+    char *s;
+    int value;
+
+    va_start (list, fmt);
+
+    while (*list) {
+        switch (*fmt++) {
+        case 'c':
+            c = va_arg (list, int);
+
+            printf ("  Char: %c\n", c);
+            i++;
+            break;
+        case 's':
+            s = va_arg (list, char *);
+
+            printf ("String: %s\n", s);
+            i++;
+            break;
+        case 'd':
+            value = va_arg (list, int);
+
+            printf (" Value: %d\n", value);
+            i++;
+            break;
+        default:
+            printf ("Unknown format character\n");
+        }
+    }
+
+    va_end (list);
+
+    return i;
+}
+
+int main (int argc, char **argv)
+{
+
+    printf ("Number of Parameter: %d\n", params ("Xcssssd", 'I', "made", "this", "application", "in", 2008, NULL));
+
+    return EXIT_SUCCESS;
+}