🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.os2.programmer
Article #2372

Re: C Programming Question

#2372
From: Joe Herman
Date: Thu, 17 Jan 1991 23:46
38 lines
1812 bytes
From article <9009@uwm.edu>, by tanith@csd4.csd.uwm.edu (Michael D Kretzer):
> I don't know whether this question as much to do with OS/2 as with
> C programming,

You're right, it really belongs in comp.lang.c, but here goes....


> ...to declare 256 pointers to strings, each with 256 bytes allocated.
> I was wondering if you could declare this from one command, or if
> you have to declare char *Array[256] and then malloc the memory in
> a loop for each string.

If you do not need the 256 byte arrays to be contiguous with each
other, you're much better off using "char *array[256]" and then
mallocing memory for each pointer.  If, for some reason, you do need
the arrays to be contiguous, then malloc a large block of memory (256
x 256) and assign array[x] = &foo[x*256] where 0 <= x < 256.

The reason you can not do what you want is that malloc returns a single
pointer.  You want malloc to return an array of pointers, which is not
it's purpose.

Oh yes, just to make this somewhat OS/2 relevant, does anyone know if
OS/2 2.0 is supposed to be 32 bit?  Can we get rid of "huge" arrays then?



			Have fun,
			Joe H.
			U. of Maryland

dzoey@terminus.umd.edu

P.S.  I've directed followups to comp.lang.c


-- 
"Everything is wonderful until you know something about it."
Technical Details
Message-ID: <7871@umd5.umd.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!noose.ecn.purdue.edu!mentor.cc.purdue.edu!purdue!haven!umd5!terminus.umd.edu!dzoey
References: <9009@uwm.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!noose.ecn.purdue.edu!mentor.cc.purdue.edu!purdue!haven!umd5!terminus.umd.edu!dzoey
From: dzoey@terminus.umd.edu (Joe Herman)
Newsgroups: comp.os.os2.programmer
Subject: Re: C Programming Question
Message-ID: <7871@umd5.umd.edu>
Date: 17 Jan 91 23:46:38 GMT
References: <9009@uwm.edu>
Sender: news@umd5.umd.edu
Followup-To: comp.lang.c
Distribution: na
Organization: University of Maryland DOSIP-CSC
Lines: 38