我有一个函数声明一个字符数组,然后为它赋值,然后将衰减的指针传递给另一个func,就像这个伪c代码一样,这样如果我在{{1}内printf("country %s," country)
它给了我"德国"
anotherfunc
如何将调用移到somefunc之外的anotherfunc并仍能传递country char数组?现在,void somefunc()
{
...
char *country = NULL;
country = "GERMANY"
...
anotherfunc(country); //printf("country %s," country)` == GERMANY
}
正在给我printf("country %s," country)
(null)
答案 0 :(得分:1)
将指针传递给指针:
void somefunc(char **pcountry) {
*pcountry = "GERMANY";
}
并将其命名为
somefunc(&country);