author | Markus Bröker <mbroeker@largo.dyndns.tv> |
Thu, 16 Apr 2009 12:49:11 +0200 | |
changeset 36 | f52a9deddfc0 |
parent 29 | 7abf6146898e |
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; |
|
27
81a574d60c15
typo in min2time format string
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
13 |
|
0 | 14 |
va_list list; |
27
81a574d60c15
typo in min2time format string
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
15 |
|
0 | 16 |
char c; |
17 |
char *s; |
|
27
81a574d60c15
typo in min2time format string
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
18 |
|
0 | 19 |
int value; |
20 |
||
21 |
va_start (list, fmt); |
|
22 |
||
23 |
while (*list) { |
|
24 |
switch (*fmt++) { |
|
25 |
case 'c': |
|
26 |
c = va_arg (list, int); |
|
27 |
||
28 |
printf (" Char: %c\n", c); |
|
29 |
i++; |
|
30 |
break; |
|
31 |
case 's': |
|
32 |
s = va_arg (list, char *); |
|
33 |
||
34 |
printf ("String: %s\n", s); |
|
35 |
i++; |
|
36 |
break; |
|
37 |
case 'd': |
|
38 |
value = va_arg (list, int); |
|
39 |
||
40 |
printf (" Value: %d\n", value); |
|
41 |
i++; |
|
42 |
break; |
|
43 |
default: |
|
44 |
printf ("Unknown format character\n"); |
|
45 |
} |
|
46 |
} |
|
47 |
||
48 |
va_end (list); |
|
49 |
||
50 |
return i; |
|
51 |
} |
|
52 |
||
53 |
int main (int argc, char **argv) |
|
54 |
{ |
|
55 |
||
56 |
printf ("Number of Parameter: %d\n", params ("Xcssssd", 'I', "made", "this", "application", "in", 2008, NULL)); |
|
57 |
||
58 |
return EXIT_SUCCESS; |
|
59 |
} |