| www.delorie.com/archives/browse.cgi | search |
| X-Authentication-Warning: | delorie.com: mailnull set sender to djgpp-bounces using -f |
| From: | "Jake" <LightningRider AT 1st DOT net> |
| Newsgroups: | comp.lang.c,comp.os.msdos.djgpp |
| Subject: | Pointer Blues |
| Lines: | 52 |
| X-Priority: | 3 |
| X-MSMail-Priority: | Normal |
| X-Newsreader: | Microsoft Outlook Express 5.00.2615.200 |
| X-MimeOLE: | Produced By Microsoft MimeOLE V5.00.2615.200 |
| Message-ID: | <ZNN28.965$903.5465@news> |
| Date: | Mon, 21 Jan 2002 05:36:57 GMT |
| NNTP-Posting-Host: | 64.89.13.189 |
| X-Trace: | news 1011591417 64.89.13.189 (Mon, 21 Jan 2002 00:36:57 EST) |
| NNTP-Posting-Date: | Mon, 21 Jan 2002 00:36:57 EST |
| To: | djgpp AT delorie DOT com |
| DJ-Gateway: | from newsgroup comp.os.msdos.djgpp |
| Reply-To: | djgpp AT delorie DOT com |
Pointers are begining to drive me crazy.
Ok here's the problem, I needed two 2 dimensional arrays that are visual to
all
the functions. So I defined two 'pointer-to-pointer' varibles of type int,
thats what 2 dimensional arrays really are, 'pointers-to-pointer' right?
That problem is the that whatever value I asign to one array shows up in the
array, I can have have this.
If someone can follow the code and know whats going on please help me out.
thanks
Jake
#include <stdio.h>
int columns = 8;
int rows = 8;
int **map;
int **mask;
void initarray(int **arr); // allocates memory
void display(int **arr);
int main(int argc, char *argv[])
{
int x,y;
initarray(map);
initarray(mask);
for ( y = 0; y < rows;y++)
for (x=0;x<columns;x++){
map[x][y] = x;
mask[x][y] =x*2;
}
display(map);
display(mask);
return 0;
}
void display(int **arr)
{
int x,y;
for (y=0; y<rows; y++){
for (x=0; x < columns; x++)
printf("%3d",arr[x][y]);
puts("");
}
puts("");
}
void initarray(int **arr)
{
int x;
for (x=0;x<columns;x++)
arr[x] = (int *)calloc(rows, sizeof(int));
}
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |