Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!elroy.jpl.nasa.gov!jarthur!nntp-server.caltech.edu!suncub.bbso.caltech.edu!EYCHANER From: eychaner@suncub.bbso.caltech.edu (Amateurgrammer) Newsgroups: comp.lang.c Subject: Malloc and arrays... Message-ID: <1991Mar3.172942.3116@nntp-server.caltech.edu> Date: 3 Mar 91 17:29:42 GMT Sender: news@nntp-server.caltech.edu Reply-To: eychaner@suncub.bbso.caltech.edu Organization: Big Bear Solar Observatory, Caltech Lines: 26 Warm up those flame guns! It's time for Another Novice Question! I know this is partly covered in the FAQ, but it didn't seem to have quite the answer I want. I know that if I malloc a chunk of memory, like so: char *bigmemory; bigmemory = (char *) malloc (OODLES_O_BYTES); I can access the chunk of memory as though it were an array, like so: bigmemory [RIGHT_HERE] = SOME_CHARACTER; (I hope I have this right. This should decompose to: *(bigmemory + RIGHT_HERE) = SOME_CHARACTER; shouldn't it?) So how can I access it as a 2D array, like so: bigmemory [RIGHT_HERE][RIGHT_NOW] = SOME_CHARACTER; I know I could use, for example: *(bigmemory + RIGHT_HERE * SIZEOF_RIGHTNOW + RIGHT_NOW) = SOME_CHARACTER; but all my previous code (which uses the 2D array) would then have to be changed. And it looks much nicer (when RIGHT_HERE and RIGHT_NOW are big, nasty expressions) in 2D array format. And don't flame me for "writing bad code"; it was written during a kinder, gentler period. I'm doing the best that I can, learning as I go along. -Glenn :-) Glenn Eychaner - Big Bear Solar Observatory - eychaner@suncub.bbso.caltech.edu "You Have the Right to Remain DEAD." -The Simpsons