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