#include <iostream> #include <Windows.h> #include <string.h> using namespace std; void reverse(unsigned char *a) { unsigned char *p1=a; unsigned char tmp[1024]; unsigned char *p2; unsigned int len=strlen((char *)a); p2=len+tmp;//传的是地址,等式左边不能是指针 *p2--='\0'; while(*p1) { if(*p1<0x80) { *p2--=*p1++; }else { *(p2-1)=*p1++; *p2=*p1++; p2=p2-2; } } for(int i=0;i<len;i++) { a[i]=tmp[i]; } } int main(void) { unsigned char str[1024]; cout<<"请输入你要转换的字符:"; cin>>str; reverse(str); cout<<"转换的结果为:"<<str<<endl; system("pause"); return 0; }
运行结果: