MAllocate help
01-Dec-94 08:46:06
Sb: #44427-MAllocate help
Fm: Mal Lansell 74222,3046
To: Theo Klaassen 75152,2572
Theo,
There is no bug in the while loop (apart from the last printf when n==0).
Struct record *array is treated in the program as an array of record structs.
Therefore array[n].name is the correct notation to use.
Henry's code works fine if you compile it, as long as you keep the size of the
malloc below 32768. If I remember correctly, the malloc function takes a
signed int as its argument, so his compiler must be taking 33300, treating it
as a signed int (ie -32236), and then allocating a memory area of 32236 bytes.
This would account for the last few values being corrupted, and causing the
crashes that he complained of a few days ago.
The solution is either to have a smaller array, or to allocate the memory as
part of the program with
struct record array[892];
The rest of the program can remain unchanged.
Mal
Binary Dreams