Q: This code, straight out of a book, isn't compiling:
int f()
{
char a[] = "Hello, world!";
}
A: Perhaps you have an old, pre-ANSI compiler, which doesn't allow initialization of ``automatic aggregates'' (i.e. non-static local arrays, structures, or unions). You have four possible workarounds:
f()
{
char *a = "Hello, world!";
}
You
can always initialize local char * variables
to point to
string literals
(but
see question
1.32).
f()
{
char a[14];
strcpy(a, "Hello, world!");
}
See also question 11.29a.