I don't know, how to solve this problem. I have to use malloc inside void function. How can I use free for this case?
#include <stdio.h>
#include <stdlib.h>
void function(char **string)
{
*string=malloc(16*sizeof(char));
*string="Hello World";
}
int main ()
{
char *string;
function(&string);
printf ("%s\n", string);
free(string); //not working
return 0;
}
I can't use malloc inside function, because I would lose my string. And I don't know, how to use free in main. Can someone help me?