Path: utzoo!censor!geac!torsqnt!lethe!yunexus!ists!helios.physics.utoronto.ca!news-server.csri.toronto.edu!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!swrinde!ucsd!nosc!crash!kevin@crash.cts.com From: kevin@crash.cts.com (Kevin Hill) Newsgroups: comp.lang.c Subject: How do I use Malloc to dynamically create a two dimensional array Message-ID: <7046@crash.cts.com> Date: 18 Jan 91 21:13:16 GMT Sender: root@crash.cts.com Lines: 34 I have a problem, and it may seem basic, but how do I use malloc to create an array of type int i[100][100]; Should I use a pointer to a pointer like int (*i)[100]; or should I use int **i; I have been told that the following will work, int **i; for (x = 0; x < 100; x++) { i[x] = malloc(sizeof(int)*100); } but it seems to me that this would be a very sloppy way to define the whole array. It could end up giving you an array that is all over the place in memory. So, If you will please bear with me on this question, thanks, as the three or four books that I do have on C, don't seem to go into great detail in allocating two dimensional arrays dynamically... Thanks.. ******************************************************************************* * Kevin Hill * San Diego State University, Accounting Major. * No matter where you go, there you are. ******************************************************************************* * \ * *=====+)--------------------------- * / * San Diego State Fencing *******************************************************************************