justinlm 2010年11月27日
Windows 字符串反转的问题


#include "stdafx.h"

BOOL StringReverseW(PWSTR pWideCharStr, DWORD cchLength);

int _tmain(int argc, _TCHAR* argv[])
{
PWSTR pWideCharStr = _T("String");

StringReverseW(pWideCharStr,8);
printf("StringReverseW the pWideCharStr: %s",pWideCharStr);

return 0;
}

//宽字节字符串颠倒算法
BOOL StringReverseW(PWSTR pWideCharStr, DWORD cchLength) {

// Get a pointer to the last character in the string. cchLength:最大允许的字节数
PWSTR pEndOfStr = pWideCharStr + wcsnlen_s(pWideCharStr , cchLength) - 1;
wchar_t cCharT;
// Repeat until we reach the center character in the string.
while (pWideCharStr < pEndOfStr) { //我不知道为什么是这么判断,感觉这样不对呀?
// Save a character in a temporary variable.
cCharT = *pWideCharStr;

// Put the last character in the first character.
*pWideCharStr = *pEndOfStr; //调式时候,这里会出现异常

// Put the temporary character in the last character.
*pEndOfStr = cCharT;

// Move in one character from the left.
pWideCharStr++;

// Move in one character from the right.
pEndOfStr--;
}

// The string is reversed; return success.
return(TRUE);
}



while (pWideCharStr < pEndOfStr) //我不知道为什么是这么判断,感觉这样不对呀?

*pWideCharStr = *pEndOfStr; //调式时候,这里会出现异常

大侠急救呀!
...全文
94 点赞 收藏 8
写回复
8 条回复

还没有回复,快来抢沙发~

发动态
发帖子
VC/MFC
创建于2007-09-28

7889

社区成员

42.1w+

社区内容

VC/MFC相关问题讨论
社区公告
暂无公告