Path: utzoo!censor!geac!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!usc!apple!bionet!ucselx!crash!kevin@crash.cts.com From: kevin@crash.cts.com (Kevin Hill) Newsgroups: comp.sys.mac.programmer Subject: Using Malloc to create variables. help? Message-ID: <6996@crash.cts.com> Date: 17 Jan 91 09:26:04 GMT Sender: root@crash.cts.com Lines: 54 All right guys, another question and this time i'll give you the whole thing, like a function... Here it is. I extern int **track; extern int **map; extern char *bigmap; function() { int x,y; if ( (track = (int **)( malloc( (100 * 100) * sizeof(int) + 1) )) == NULL) ExitToShell(); if ( (map = (int **)( malloc( (100 * 100) * sizeof(int) + 1 ) )) == NULL) ExitToShell(); if ( (bigmap = (char *)( malloc( (100 * 100 * 32) * sizeof(char) + 1 ) )) == NULL) ExitToShell(); for (x = 0;x < 100; x++) for(y =0; y < 100; y++) { map[x][y] = -1; track[x][y] = -1; } }} there you go. Now the problem is that when the for loops go to initialize the variables, it crashes with various error codes in the debugger. Any hints, did I declare track, map, and bigmap correctly. Bigmap is eventiually going to be a 100 by 100 array of icons, (the map of my game). Also ignore the 32 size, i'll be changing that to 128 on my side. Thanks. the malloc do I need to dereference the map and track variables before I even attempt use them? I.e. like (*map)[x][y] and (*track)[x][y]? wouldn't that be the same as defining a pointer like this int *pointer = ***map; This pointer stuff is really getting wild... Thanks.. ******************************************************************************* * Kevin Hill * San Diego State University, Accounting Major. * No matter where you go, there you are. ******************************************************************************* * \ * *=====+)--------------------------- * / * San Diego State Fencing *******************************************************************************