LINUX C练习1
//如何将一个ASCII码的数据,分解为其两位16进制字符型数据,保存在一个字符数组中
#include <stdio.h>
#include <string.h>
#include <unistd.h>
int http_encode(char c,char *out)
{
int j = 0;
char hex_table[16] = "0123456789abcdef";
out[j] = hex_table[c >> 4];
j++;
out[j] = hex_table[c & 0x0f];
j++;
out[j] = '\0';
return 0;
}
int main()
{
char c;
printf("Please input:");
scanf("%c",&c);
char outurl[10] = "";
http_encode(c,outurl);
printf("*0x%s*\n",outurl);
return 0;
}
欢迎访问:wenhao.ink