当我尝试编译以下代码时,我收到一个错误:“在指定的行(<<<<<)中发现argument 1 to 'allocate'; found 'char * *', expected 'char *'.” 欢迎解释。
#include <stdio.h>
#include <string.h>
void allocate(char *dt);
int main(void)
{
char *data[3];
allocate(data); <<<<<
return 0;
}
void allocate(char *dt)
{
int i;
char buf[] = "A test string";
for (i = 0; i < 3; i++){
strcpy(&dt[i], buf);
printf("%s\n", dt[i]);
}
}
我的理解是我应该这样调用allocate函数: allocate(&data),但是出现了以下错误:"Type error in argument 1 to 'allocate'; found 'char * (*)[3]', expected 'char *'"。
很明显,我想让*data[]的内容等于buf。