** help...

R. Kym Horsell vu0310 at bingvaxu.cc.binghamton.edu
Tue Aug 21 12:32:28 AEST 1990


In article <2409 at dsacg2.dsac.dla.mil> nol2321 at dsacg2.dsac.dla.mil (Jim Dunn) writes:
\\\
>/* the problem is next */
>	w1->array = malloc( xL * sizeof(int) );
>/* isn't the above line legal, or how can I allocate mem for the storage */
\\\

The first, minor, problem is that you haven't declared the prototype
for malloc(). You'd better say

	extern char *malloc();

at the top or include the appropriate header (malloc.h is std but
some PCs use alloc.h). This'll fix other problems when you
try to change memory models.

The main problem is that you didn't allocate the array, only
the *rows* of the array. Better put

	w1->array = (int**)malloc(10 * sizeof(int*));

before the for-loop; otherwise there isn't anywhere for the 
``row-of-rows'' to be stored!

The final point: inside the for-loop you have said the
array elements are int* -- i gather you really want to store ints
in them so:

	w1->array[x] = (int*)malloc(10*sizeof(int));

Hope this helps,
-Kym Horsell

P.S. please don't edit the "Newsgroups" line.



More information about the Comp.lang.c mailing list