我在反转 LPSTR 时遇到一些问题。 这是我的功能:
LPSTR Reverse(LPSTR a_lpText)
{
int nTextLength = strlen((char*)a_lpText);
LPSTR lpReversed = (LPSTR) GlobalAlloc(GPTR, nTextLength + 1);
for (int i = 0; i < nTextLength; ++i)
*(lpReversed + i) = (CHAR) *(a_lpText + nTextLength - i);
return lpReversed;
}
函数,返回未初始化的LPSTR或一些奇怪的字符。 问题可能出在转换上?谢谢各位的解答!
编辑 1:strcat() 不起作用。我只想逐个字符地复制。
编辑2:
*(lpReversed + i) = (CHAR) *(a_lpText + nTextLength - i - 1);
卡住整个程序。
最佳答案
试试这个)
*(lpReversed + i) = (CHAR) *(a_lpText + nTextLength - i - 1);
最好检查 a_lpText 是否为 NULL 和零长度!
关于c++ - (C++/WinAPI) 反转 LPSTR,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12883035/