| delorie.com/archives/browse.cgi | search |
| X-Authentication-Warning: | delorie.com: mailnull set sender to djgpp-bounces using -f |
| From: | pete <pfiland AT mindspring DOT com> |
| Newsgroups: | comp.lang.c,comp.os.msdos.djgpp |
| Subject: | Re: Pointer Blues |
| Date: | Mon, 21 Jan 2002 09:51:00 -0500 |
| Organization: | PF |
| Lines: | 26 |
| Message-ID: | <3C4C2AD4.7344@mindspring.com> |
| References: | <ZNN28.965$903 DOT 5465 AT news> <3C4C2580 DOT 6F2C AT mindspring DOT com> |
| NNTP-Posting-Host: | 3f.35.7c.59 |
| Mime-Version: | 1.0 |
| X-Server-Date: | 21 Jan 2002 14:52:21 GMT |
| X-Mailer: | Mozilla 3.04Gold (Win95; I) |
| To: | djgpp AT delorie DOT com |
| DJ-Gateway: | from newsgroup comp.os.msdos.djgpp |
| Reply-To: | djgpp AT delorie DOT com |
pete wrote:
> int **initarray(int columns, int rows)
> {
> int x, **arr;
> arr = malloc(columns * sizeof(int*));
> arr[x] = malloc(rows * sizeof(int));
arr = malloc(columns * sizeof *arr);
and
arr[x] = malloc(rows * sizeof *arr[x]);
are slightly more better ways of writing those lines.
since then all you would have to do, to change the function
from initializing a 2 dimensional array of int,
to initializing a 2 dimensional array of anything, doubles for example,
would be to change:
int x, **arr;
to
int x;
double **arr;
--
pete
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |