As in the question at "Excess elements of scalar initializer for pointer to array of ints", I too am working on Ex. 5–9 in K&R, trying to convert
static char daytab[2][13] = {
{0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
{0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
};
into
static char *daytab[] = {
{0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
{0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
};
and am getting the errors described there. However, the accepted answer of
static char arr[2][3] = { { 1, 2, 3 }, { 4, 5, 6 } };
static char (*ptr)[3] = NULL;
ptr = arr;
just gives me another error at ptr = arr
of
error: data definition has no type or storage class
Can anyone help?
Also, why is it legal to use an array of pointers to char
arrays, such as
static char *name[] = {
"Illegal month",
"January", "February", "March",
"April", "May", "June",
"July", "August", "September",
"October", "Novemer", "December"
};
but not int
arrays?