我遇到了关于如何反转包含此“abcd汉字efg”的字符串的问题。
str_to_reverse = "abcd汉字efg"; /* those non-ASCII chars are Chinese characters, each of them takes 2 bytes */
还原后应该是:
str_toreverse = "gfe字汉dcba";
我想,要反转字符串,我必须识别那些非 ASCII 字符,因为我认为简单地反转每个字节不会得到正确的答案。
我该怎么做?
PS:我在 32 位 Ubuntu 下编写了这个程序。然后我打印了每个字节:
for(i = 0; i < strlen(s); i++)
printf("%c", s[i]);
我得到了一些乱码而不是“汉字”。