UTF8编码转汉字
int hexToDec(char c)
{
if (c >= '0' && c <= '9')
return c - '0';
if (c >= 'a' && c <= 'f')
return c - 'a' + 10;
if (c >= 'A' && c <= 'F')
return c - 'A' + 10;
return 0;
}
void decodeMsg(char* to, char* from)
{
for (; *from != '\0'; ++to, ++from)
{
if (from[0] == '%' && isxdigit(from[1]) && isxdigit(from[2]))
{
*to = hexToDec(from[1]) * 16 + hexToDec(from[2]);
printf("to: %s\n", to);
from += 2;
}
else
{
*to = *from;
}
}
*to = '\0';
}
int main()
{
char *testbuf = "htpLinux%E5%86%85%E6%A0%B8%E6%88%91%E7%88%B1%E4%BD%A0.jpg";
char decodedBuf[1024];
decodeMsg(decodedBuf,testbuf);
printf("testbuf: %s\n", decodedBuf);
return 0;
}