author | Markus Bröker <mbroeker@largo.dyndns.tv> |
Sat, 13 Dec 2008 17:58:03 +0100 | |
changeset 10 | f19f44e2e863 |
parent 9 | c3fecc82ade6 |
child 27 | 81a574d60c15 |
permissions | -rw-r--r-- |
9
c3fecc82ade6
standard tags for git projects
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
1 |
/** |
c3fecc82ade6
standard tags for git projects
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
2 |
* test/demos/varargs.c |
c3fecc82ade6
standard tags for git projects
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
3 |
* Copyright (C) 2008 Markus Broeker |
0 | 4 |
*/ |
5 |
||
6 |
#include <stdio.h> |
|
7 |
#include <stdlib.h> |
|
8 |
#include <stdarg.h> |
|
9 |
||
10 |
int params (char *fmt, ...) |
|
11 |
{ |
|
12 |
int i = 0; |
|
13 |
va_list list; |
|
14 |
char c; |
|
15 |
char *s; |
|
16 |
int value; |
|
17 |
||
18 |
va_start (list, fmt); |
|
19 |
||
20 |
while (*list) { |
|
21 |
switch (*fmt++) { |
|
22 |
case 'c': |
|
23 |
c = va_arg (list, int); |
|
24 |
||
25 |
printf (" Char: %c\n", c); |
|
26 |
i++; |
|
27 |
break; |
|
28 |
case 's': |
|
29 |
s = va_arg (list, char *); |
|
30 |
||
31 |
printf ("String: %s\n", s); |
|
32 |
i++; |
|
33 |
break; |
|
34 |
case 'd': |
|
35 |
value = va_arg (list, int); |
|
36 |
||
37 |
printf (" Value: %d\n", value); |
|
38 |
i++; |
|
39 |
break; |
|
40 |
default: |
|
41 |
printf ("Unknown format character\n"); |
|
42 |
} |
|
43 |
} |
|
44 |
||
45 |
va_end (list); |
|
46 |
||
47 |
return i; |
|
48 |
} |
|
49 |
||
50 |
int main (int argc, char **argv) |
|
51 |
{ |
|
52 |
||
53 |
printf ("Number of Parameter: %d\n", params ("Xcssssd", 'I', "made", "this", "application", "in", 2008, NULL)); |
|
54 |
||
55 |
return EXIT_SUCCESS; |
|
56 |
} |