Pointers and Arrays

From: Warren Robbins (robbinsw@ucs.orst.edu)
Date: 12/29/99


Hi all,

   It is now time for me to ask a question that I've been having trouble
with for a long time.  It is more of a C question, but it pertains to
CircleMUD because of the overworld map I'm making for it, and the
generator I'm working on.
   What I'm doing is parsing room descriptions out of a file, assigning
them to a code, and then getting a character map and writing the world
file and exits based on it.  For example:

#k
<valid room file to accompany>
S
#m
<valid room file to accompany>
S
-
5x5
kkkkk
kkkmk
kkmkk
kmkkk
kkkkk

Now my program can take and make rooms and assign vnums and doors from the
map, but here lies my problem (sorry for beating around the bush):

How can I get a valid 2-d variable sized array.  For example, reading the
file above would determine I need:
char map[5][5];

However, C won't let me pass the size as arguments and create the variable
based on those arguments to a function.

I tried memory allocation, like this:
char **matrix;

(*matrix) = (char *)malloc(sizeof(char) * height);
(matrix) = (char *)malloc(sizeof(char) * width);

I get an error on the second malloc() line, about `assignment from
incompatible pointer type'.

It seems to be something simple, but it's eluding me, so I appreciate any
help that can be given.

--
Tony Robbins          | Kupoppo.Net (under construction/currently down)
robbinsw@ucs.orst.edu | http://kupoppo.dhs.net/


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     |  http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html  |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/15/00 PST