Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!wuarchive!udel!rochester!pt.cs.cmu.edu!o.gp.cs.cmu.edu!andrew.cmu.edu!rg2c+ From: rg2c+@andrew.cmu.edu (Robert Nelson Gasch) Newsgroups: comp.sys.mac.programmer Subject: Re: malloc() Help Message-ID: Date: 7 Feb 91 02:45:36 GMT References: <15828@milton.u.washington.edu> Organization: Class of '91, Carnegie Mellon, Pittsburgh, PA Lines: 23 In-Reply-To: <15828@milton.u.washington.edu> >For some reason, I have trouble using malloc() in THINK C. >Here is an example: >doit(num) >int num; >{ > char *back; > > back=malloc(num); >} >If you know what is wrong with the code PLEASE E-mail me and tell me what >I need to fix. Thank you. Your call to malloc() can't work because the syntax is wrong. You have to specify the type of pointer you wish to create. Example. back = (char *) malloc (num); If you want to malloc() memory for a structure, you'd use the sizeof() function Example: back = (struct_name *) malloc (sizeof (struct_name)); Hope this helps --> Rob