varargs.c
author Markus Bröker <mbroeker@largo.dyndns.tv>
Sat, 13 Dec 2008 17:58:16 +0100
changeset 23 7acfc5eda7ed
parent 9 c3fecc82ade6
child 27 81a574d60c15
permissions -rw-r--r--
this seems to be the proper way under ms, but it won't work under wine committer: Markus Bröker <mbroeker@largo.homelinux.org>

/**
 * test/demos/varargs.c
 * Copyright (C) 2008 Markus Broeker
 */

#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;
}