Here's a small piece of code that I'm having some trouble with.
Code:
typedef struct my_struct {
...
int *current_items;
} my_struct;
my_struct *s = malloc(sizeof(my_struct));
s->current_items = malloc(5 * sizeof(int));
I get a compile error stating that assignment makes integer from pointer without a cast. Is this happening because I'm not casting malloc? I've seen comments on this board instructing people not to cast from malloc, so I'm a little bit lost as to what I'm doing wrong here.
Also, when I attempt to compare a pointer to a NULL value in the following manner:
Code:
if (s->current_items[1] == NULL) {
....
}
Or this:
Code:
s->current_items[1] = *p;
I also get compile errors. Do I need to cast here, or am I totally off?
Thanks.