I have a readfile
function called by main
. The criteria is I have to pass char**
into readfile
, and I have to allocate and initialize this argument inside readfile
. I am a bit confused about how to deal with char**
in a subfunction.
void main()
{
char** data;
readfile(data);
}
void readfile(char** data)
{
data = (char**)malloc(1000); //give me Segmentation fault
data = (char*)malloc(1000); //give me " warning: assignment from incompatible pointer type" during compliation.
data = (char)malloc(1000); //give me "warning: cast from pointer to integer of different size" during compilation.
}
I tried to cast a pointer to it first e.g. char* pdata = *data;
and I can use pdata
ok.
How can I allocate this variable inside the readfile
function?