Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!cs.utexas.edu!uunet!pyrdc!eliot!janm From: janm@eliot.UUCP (Jan Morales/Development) Newsgroups: comp.lang.c Subject: Re: ptrs and arrays Message-ID: <429@eliot.UUCP> Date: 9 Nov 89 19:07:58 GMT References: <2640@dogie.macc.wisc.edu> <304@jhereg.Minnetech.MN.ORG> Reply-To: janm@eliot.UUCP (Jan Morales/Development) Organization: Unitech Software, Inc., Reston, VA Lines: 25 In article <304@jhereg.Minnetech.MN.ORG> Mark H. Colburn writes: >In article <2640@dogie.macc.wisc.edu> Ross Yahnke writes: >>Is there a more graceful way to do the following? I allocate >>a chunk 'o' mem and keep a ptr to it, I want to access the >>mem as an integer array and inc different elements of the array. If I read Ross' problem correctly, all you really need is: foo() { int *aPtr; char *calloc(); aPtr = (int *) calloc(NUM_OF_INTS_IN_ARRAY, sizeof(int)); aPtr[10]++; } That last line of code will increment the eleventh integer in the "chunk" of memory (aPtr[0] being the first). Keep in mind that you should check for a NULL pointer from calloc meaining there's not enough memory for your request. Jan -- {uunet,pyramid}!pyrdc!eliot!janm