[Sussex] Re: C programming help

Steve Dobson steve at dobson.org
Tue Apr 26 19:11:27 UTC 2005


Hi Cap'in

On Tue, 2005-04-26 at 11:59 +0100, Captain Redbeard wrote:
> >Steve Dobson wrote:
> >You need to insert before this line:
> >
> >   CoordArray = (Coords *) calloc(MAX_COORDS, sizeof(struct Coords));
> 
> calloc()?  That's a new one.  Based on the advice I was given at the weekend
> I've been using:
> 
> 
>     CoordArray = malloc ((sizeof (struct Coords) * MAX_COORDS));
> 
> Is calloc() the equivalent or does it work different in any way?

If you're using a reasonable system then you should have the man pages
for all the library calls - but in case you haven't:

    NAME
       calloc - Allocate and free dynamic memory

    SYNOPSIS
       #include <stdlib.h>

       void *calloc(size_t nmemb, size_t size);
       void *malloc(size_t size);

    DESCRIPTION
       calloc()  allocates memory for an array of nmemb elements of size
       bytes each and returns a pointer to the allocated memory.  The
       memory is  set to zero.
       
       malloc()  allocates  size  bytes and returns a pointer to the
       allocated memory.  The memory is not cleared.

> Anyway, I'm probably jumping in at the deep end a bit with this program as
> it uses a LOT of dynamic memory allocation and pointer to structs and functions
> but I'm learning fast, the painful way, so I think it's "ALMOST THERE (TM)."

I bet you're not "almost there".  You still have a lot to learn young
programmer.  I base that comment on my own experence.  :-)

> Stay tuned!

shouldn't that be dry docked?  :-)

Steve





More information about the Sussex mailing list