Recall that in C, a string is a NULL-terminated array of characters. Therefore, if we wanted to store multiple strings in an array, we’d need an array of strings, which is an array of arrays! This is also called a two-dimensional array.
Such an array of strings is declared as follows:
char name[NRECS][STRLEN];
Here, name is the name of the array, NRECS the number of strings to store, and STRLEN a bound on the length of the strings to be stored (remember to leave room for the NULL-terminator).
Table24.1.An Array of Strings
P
e
t
r
a
\0
A
l
e
x
\0
C
h
o
c
o
l
a
t
e
\0
The above sample table has STRLEN=10 and NRECS=5.
You could #defineNRECS and STRLEN at the top of your program if you wish, so that you could easily change these constants. For example: