【发布时间】:2016-05-24 14:47:32
【问题描述】:
我有以下原型:
int Split(const char* str, const char* delim,unsigned int& numtokens,char **tokensRes)
最后一个参数用于返回此函数的响应。在函数中我们有以下内容:
.
.
char **tokens =(char**) calloc(tokens_alloc, sizeof(char*));
.
.
.
//at the end of the code
tokensRes = tokens;
.
当函数的返回是char**时直接返回tokens变量的值我得到了正确的答案,但是使用上面的方法返回的函数是空的。如何让这个功能正常工作?
编辑 1: 我的意图是接收一个 char 数组,例如:
array[0] = "ABC"
array[1] = "ABC"
array[2] = "ABC"
array[3] = "ABC"
【问题讨论】:
-
我使用指向指针的指针,因为我需要一个 char 数组的数组
-
您要返回字符串还是字符串数组?
-
在
char **tokens =中删除一个*,因为您正在分配一个指向字符的指针。为什么不使用引用? -
由于我们没有看到该功能,因此很难告诉您如何更正它。发一个真实的MCVE。
标签: c++ function double-pointer