Help with malloc() ...

LAVITSKY at RU-BLUE.ARPA LAVITSKY at RU-BLUE.ARPA
Fri Aug 10 05:41:59 AEST 1984


From:  Eric <LAVITSKY at RU-BLUE.ARPA>

Hi,

 I'm quite a novice  to C, and  would like to  know if anyone  could
help me with the following:

  I need to allocate memory space for some buffers in the  following
manner: In the middle of my program I read in some parameters from a
file which  will  determine  the  size  of  my  buffer  space.   The
parameters are two  integers -  and the buffer  itself will  contain
integers.  So, if I read in a value of 8192 from my file header -  I
need to then allocate  my buffers to be  exactly 8192 bytes of  type
integer.  I will  also be reading  data into the  buffers from  this
file. How do I use malloc() to allocate my buffer space ? Everything
I read so far is very vague as to how this is used. I would like  to
read data  into  the array  and  allocate  each byte  of  the  array
dynamically as it is needed. Something like:

	get buffer size;
	loop:
		allocate buffer byte;
		read data into buffer;
	untill buffer size;

Thanx,
Eric
-------



More information about the Comp.lang.c mailing list