0

It won't allow me to initialize the array to NULL in the struct in the header file:

typedef struct frog
{
    bool is_frog;
    struct frog* french_chef[10]; // eg = {NULL};
} frog;

which I get, but it also won't let me do it in the main function:

frog* root = malloc(sizeof(frog));
root->french_chef = {NULL};

Where is my logic error? I'd like to learn what I'm confused about before moving on to correcting it. I've read a few alternatives like memset and calloc, but memset seems inefficient and I'm not confident that calloc assigning zero's to everything will allow me to evaluate for NULL or \0 in the array later on in main.

2
  • I think the alternatives you mention are your best bet. calloc() will initialize your pointers to NULL don't worry. Or create a for loop that assigns french_chef[i] = NULL; for i from 0 to 9..
    – ChrisG
    Jul 30, 2015 at 13:53
  • Keep in mind that calloc() is faster that malloc() + memset().
    – ChrisG
    Jul 30, 2015 at 13:53

0

You must log in to answer this question.

Browse other questions tagged .