I am trying to free the elements of a struct, which has size_t variables and char. How do free the size_t ones, because I keep getting warnings like
[Warning] passing arg 1 of `free' makes pointer from integer without a cast
Now I understand that i need to make a cast, but I don't know how! Here's the code:
typedef struct collection
{
char **c;
size_t nc, na, ne;
} TCS, * ACS;
void Destroy(ACS *x)
{
int i;
free((*x)->na);
for(i=0;i<(*x)->nc;i++)
free((*x)->c[i]);
free((*x)->c);
free((*x)->nc);
free((*x)->ne);
}
/* allocating */
ACS AlocCS(size_t d, size_t e)
{
ACS *af=(ACS*)malloc(d);
if(af==NULL)
return 0;
(*af)->na=e;
(*af)->nc=d;
(*af)->c=(char**)calloc(e*d,sizeof(char));
if((*af)->c==NULL){
free(af);
return 0;}
return *af;
}
I am getting 3 warnings, all related to na,ne,nc. What am I skipping? Thanks!
LE: thanks everyone, my project works now ! Happy holidays!
I am getting 3 warnings, all related to na,ne,nc. What am I skipping?
malloc
returns a pointer to a dynamic allocated memory area. size_t
variables can't hold such addresses.
You just need to free what you alloced, ie (*af)->c
and af
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With