Re: Pointers and Arrays

From: Rohan Wallace (
Date: 12/29/99

> 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'.

OK. well from a purely C point of view the second line should read:
(matrix) = (char **)malloc(sizeof(char *) * width);

Secondly, (someone feel free to correct if they think I'm wrong)
But I would swap the order of the two lines since I prefer to
allocate memory for the list of pointers first.

Rohan Wallace
System Programmer                  222 Grote Street
SE Network Access                  Adelaide SA 5000

     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     |  |

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