【发布时间】:2015-04-25 04:24:05
【问题描述】:
wcstok_s函数是如何实现的?
wcstok函数只有两个参数,第二次调用时如何保存字符串,第一个参数为'null'。
这两个是如何返回指针和函数结束,以及为什么保留临时内存,它会返回一个以'\0'结尾的*wchar字符串;
这是我的错误代码:
TCHAR *mywtok(TCHAR *tszText, int x, TCHAR *tnext) {
TCHAR res[1005];
if (tszText == nullptr)
tszText = tnext;
int len = wcslen(tszText);
int rlen = 0;
for(int i = 0; i < len; i++){
if (tszText[i] != x) {
res[rlen++] = tszText[i];
}
else {
res[rlen] = '\0';
tnext = tszText + i;
return res;
}
}
res[rlen] = '\0';
tnext = nullptr;
return res;
}
wcstok_s 是忽略 "",例如 ",,a",它会返回 "a",如果我想返回 "",则返回 "a" 或 "","","a"。
【问题讨论】: