この関数のエラーを見つけるのを手伝ってください。
wchar_t* clean(wchar_t out[], const wchar_t in[])
{
int n = wcslen(in);
wchar_t *str = new wchar_t[n];
wcscpy(str, in);
out[0] = L'\0';
wchar_t *state;
wchar_t *word = wcstok(str, L" ", &state);
while (NULL != word) {
if (wcslen(word) > 1) {
wcscat(out, word);
wcscat(out, L" ");
}
word = wcstok(NULL, L" ", &state);
}
delete state;
delete[] str;
return out;
}
この関数は、元の文字列の単語を取得し、結果の文字列に入れます。関数のほかに、複数のスペースと単一の文字からの単語を無視します。
残念ながら、プログラムは同じエラーでこの関数の最後の行に落ちます (linux-3.7、gcc-4.7):
*** Error in `./a.out': free(): invalid next size (fast): 0x08610338 ***
私が間違っていたことを説明してください。