How do you do this???

John Snow snow at china.uu.net
Sat Dec 9 07:19:38 AEST 1989


I am writing a program where I need to dynamically allocate memory for
an array of strings (ie list[x][10]), but I can't seem to please the
compiler.  I want to be able to use it in the form:

for (x = 0; x < n; x++)
	strcpy (list[x], source[x]);

As a first shot I tried:

typedef ARRAY[][10];
...
{
ARRAY list;  /* tried both 'list' and '*list' */

	list = calloc (5, 10);
...
}

The compiler was not at all impressed with that.  After trying several
things I finally found one that at least compiles and runs, even
though the compiler does gripe about it.  That is:

{
char (*list)[10];

	list = calloc (5, 10);
...
}

Even thought this *seems* to work, I don't have a warm-fuzzy because
of the compiler warning.  Could somebody tell me how to do this in a
clean way?  Any suggestions would be greatly appreciated.

Thanks,
		John
-- 
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: John Snow  - MDC          | any opinions are purely accidental
:: Denver, Colorado          | and not the fault of the management
:: Try mailing to: [snow at china.uu.net] or maybe [uunet!china!snow]



More information about the Comp.lang.c mailing list