c语言求助,关于反序问题
输入字符串str,倒叙输出str,注意支持中文,例如 “Tom吃西瓜” 输出 “瓜西吃moT”。我能单独将汉字或者字母反序,但是放在一起就做不到了,是不是应该先判定是什么类型,在反序阿!但是应该怎么判定又不知道了,麻烦看到的支支招!谢了!!
程序代码:#include <stdio.h>
#include <math.h>
#include <string.h>
int main()
{
char a[] = "我sdfasd呵sdafs呵";
char *p = a,*q;
bool s[100] = {0};
int n = 0;
while(*p)
{
if(0x80 & *p)
{
s[p-a] = true;
p+=2;
n++;
}
else
p++;
}
printf("%d\n",n);
char b[100] = {0};
if(s[strlen(a)-2])
q = a+strlen(a)-2;
else
q = a+strlen(a)-1;
int i = 0;
while(q>=a)
{
if(s[q-a])
{
b[i++] = *q;
b[i++] = *(q+1);
if(s[q-2-a])
q-=2;
else
q--;
}
else
{
b[i++] = *q;
if(s[q-2-a])
q-=2;
else
q--;
}
}
puts(b);
return 0;
}写的我好累 不过总算是实现了

程序代码:#include <wchar.h>
#include <stdio.h>
#include <conio.h>
#include <locale.h>
#define SIZE 81
typedef wchar_t WCHAR, * PWSTR;
void Reverse(PWSTR);
int main(void) {
WCHAR pwstr[SIZE];
setlocale(LC_ALL, "chs");
fgetws(pwstr, SIZE, stdin);
Reverse(pwstr);
printf("\nPress any key to continue...");
getch();
return 0;
}
void Reverse(PWSTR szpwstr) {
if(*szpwstr && *szpwstr != L'\n')
Reverse(szpwstr + 1);
wprintf(L"%c", *szpwstr);
}
