equal
deleted
inserted
replaced
1 /** |
|
2 * test/demos/varargs.c |
|
3 * Copyright (C) 2008 Markus Broeker |
|
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 |
|
14 va_list list; |
|
15 |
|
16 char c; |
|
17 char *s; |
|
18 |
|
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 } |
|