我有一个readfile
函数,调用main
。标准是我必须通过char**
到readfile
,我必须在readfile
内分配和初始化这个参数。我对如何在子功能中处理char**
有点困惑。如何在函数内初始化和分配char **参数
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.
}
我试着先投射一个指向它的指针,例如, char* pdata = *data;
我可以用pdata
ok。
如何在readfile
函数内分配这个变量?
我们不知道你的' readfile'想做的。你的代码不会读取任何文件! – 2014-08-27 18:50:23
http://stackoverflow.com/questions/2838038/c-programming-malloc-inside-another-function – jamesdlin 2014-08-28 02:18:50