There are two ways to do this. Either via static initialization using string literals like you are above:
Code Listing
#include <stdio.h>
int main(void) {
int i;
char array[9][7] = {
"[0x0a]",
"[0x09]",
"[0x0b]",
"[0x08]",
"[0x0d]",
"[0x0c]",
"[0x07]",
"[0x5c]",
"[0x22]"
};
for (i=0; i<9; i++) {
printf("%d: %s\n", i, array[i]);
}
return 0;
}
Or, using an array of pointers like so:
Code Listing
#include <stdio.h>
int main(void) {
int i;
const char* array[9] = {
"[0x0a]",
"[0x09]",
"[0x0b]",
"[0x08]",
"[0x0d]",
"[0x0c]",
"[0x07]",
"[0x5c]",
"[0x22]"
};
for (i=0; i<9; i++) {
printf("%d: %s\n", i, array[i]);
}
return 0;
}
Sample Run
0: [0x0a]
1: [0x09]
2: [0x0b]
3: [0x08]
4: [0x0d]
5: [0x0c]
6: [0x07]
7: [0x5c]
8: [0x22]
Note that in the first example, all strings are the same length (you have a bug, they should be 7-chars long to accommodate the NULL / '\0'
that terminates C-style strings), and all strings are read-write. In the second example, the strings don't need to be the same length, they can be different. They are also read-only, as are any string literals which are used in this fashion.
Recommended Reading
- Difference between declared string and allocated string, Accessed 2014-09-03,
<https://stackoverflow.com/questions/16021454/difference-between-declared-string-and-allocated-string>