author | Markus Bröker <mbroeker@largo.dyndns.tv> |
Mon, 09 Sep 2013 15:51:32 +0200 | |
changeset 166 | ecd6492274ad |
parent 140 | 05d42a3737a4 |
permissions | -rw-r--r-- |
108
d6a52e0152fb
Compont Literals in C aka Anonymous arrays
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
1 |
/** |
140
05d42a3737a4
Comments corrected: misspellings and other trivial things
Markus Bröker <mbroeker@volpe.spectre.org>
parents:
108
diff
changeset
|
2 |
* Compound literals in C aka anonymous arrays |
05d42a3737a4
Comments corrected: misspellings and other trivial things
Markus Bröker <mbroeker@volpe.spectre.org>
parents:
108
diff
changeset
|
3 |
* Copyright (C) 2008 Markus Broeker |
108
d6a52e0152fb
Compont Literals in C aka Anonymous arrays
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
4 |
*/ |
d6a52e0152fb
Compont Literals in C aka Anonymous arrays
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
5 |
|
d6a52e0152fb
Compont Literals in C aka Anonymous arrays
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
6 |
#include <stdio.h> |
d6a52e0152fb
Compont Literals in C aka Anonymous arrays
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
7 |
#include <stdlib.h> |
d6a52e0152fb
Compont Literals in C aka Anonymous arrays
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
8 |
#include <assert.h> |
d6a52e0152fb
Compont Literals in C aka Anonymous arrays
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
9 |
|
d6a52e0152fb
Compont Literals in C aka Anonymous arrays
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
10 |
static void show (char *arr[]) |
d6a52e0152fb
Compont Literals in C aka Anonymous arrays
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
11 |
{ |
d6a52e0152fb
Compont Literals in C aka Anonymous arrays
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
12 |
int i = 0; |
d6a52e0152fb
Compont Literals in C aka Anonymous arrays
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
13 |
|
d6a52e0152fb
Compont Literals in C aka Anonymous arrays
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
14 |
assert (arr != NULL); |
d6a52e0152fb
Compont Literals in C aka Anonymous arrays
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
15 |
while (arr[i] != NULL) { |
d6a52e0152fb
Compont Literals in C aka Anonymous arrays
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
16 |
printf ("arr[%d] = %s\n", i, arr[i]); |
d6a52e0152fb
Compont Literals in C aka Anonymous arrays
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
17 |
i++; |
d6a52e0152fb
Compont Literals in C aka Anonymous arrays
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
18 |
} |
d6a52e0152fb
Compont Literals in C aka Anonymous arrays
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
19 |
} |
d6a52e0152fb
Compont Literals in C aka Anonymous arrays
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
20 |
|
d6a52e0152fb
Compont Literals in C aka Anonymous arrays
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
21 |
int main (int argc, char **argv) |
d6a52e0152fb
Compont Literals in C aka Anonymous arrays
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
22 |
{ |
d6a52e0152fb
Compont Literals in C aka Anonymous arrays
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
23 |
show ((char *[]) { |
d6a52e0152fb
Compont Literals in C aka Anonymous arrays
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
24 |
"Here", "we", "go", "again", NULL}); |
d6a52e0152fb
Compont Literals in C aka Anonymous arrays
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
25 |
return EXIT_SUCCESS; |
d6a52e0152fb
Compont Literals in C aka Anonymous arrays
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
26 |
} |