实现宽字符的拷贝与计算宽字符的长度
int mywcslen(wchar_t *wstr) { int i = 0; while (*wstr!=L'\0') { i++; wstr++; } return i; } wchar_t *mywcscpy(wchar_t *dest, const wchar_t *source) { if (NULL==dest||NULL==source) { return NULL; } else { wchar_t *p = dest; while (*dest++=*source++) { } return p; } } void main() { setlocale(LC_ALL, "zh-CN");//设定中文 wchar_t *p = (wchar_t[100]){ 0 };//栈上分配上数组 c99语法 wchar_t wch2[100] = L"黑鹰-rocket"; int wlength = mywcslen(wch2); mywcscpy(p, wch2); int wplength = mywcslen(p);//拷贝之后的长度也为9 wprintf(L"\n长度:wlength=%d wplength=%d 字符串(p)=%ls\n", wlength, wplength, p); system("pause"); }
版权声明:本文为博主原创文章,欢迎指出代码不良之处,及提出代码优化方案。欢迎指点,黑夜代码,拼命奋斗,努力更新中......
时间: 2024-11-10 10:31:02