2019独角兽企业重金招聘Python工程师标准>>>
本仅调试中记录:
#include
#include
#include
#include
#include
static int Utf8ToGb2312(char *sOut, int iMaxOutLen/*BYTE*/, const char *sIn, int iInLen/*BYTE*/)
{
char *pIn = (char *)sIn;
char *pOut = sOut;
size_t ret;
size_t iLeftLen=iMaxOutLen;
iconv_t cd = iconv_open("gb2312", "utf-8");
if (cd == (iconv_t) - 1)
{
perror("iconv_open()");
return -1;
}
size_t iSrcLen=iInLen;
ret = iconv(cd, &pIn,&iSrcLen, &pOut,&iLeftLen);
if (ret == (size_t) - 1)
{
perror("iconv()");
iconv_close(cd);
return -1;
}
iconv_close(cd);
return (iMaxOutLen - iLeftLen);
}
int ChangeCharToInt(char s[],char bits[]) {
int i,n = 0;
for(i = 0; s[i]; i += 2) {
if(s[i] >= 'A' && s[i] <= 'F')
bits[n] = s[i] - 'A' + 10;
else bits[n] = s[i] - '0';
if(s[i + 1] >= 'A' && s[i + 1] <= 'F')
bits[n] = (bits[n] << 4) | (s[i + 1] - 'A' + 10);
else bits[n] = (bits[n] << 4) | (s[i + 1] - '0');
++n;
}
return n;
}
int ChangeCharToInt2(char s[],char bits[], int ct) {
int i,n = 0;
for(i = 0; i= 'A' && s[i] <= 'F'){
bits[n] = s[i] - 'A' + 10;
}else {
bits[n] = s[i] - '0';
}
++n;
}
return n;
}
typedef unsigned char uchar;
int strdosmt(char a[] ,char b[])
{
int i=0,j=0;
for(i=0;i= 0x80){
//chinese,utf-8 to gb2312
Utf8ToGb2312(f+k, 2, b+i, 3);
printf("hz--%x %x\n", f[k], f[k+1]);
i+=3;
k++;
}else{
f[k] = b[i];
printf("char--%x\n", f[k]);
k++;
i++;
}
}
return 0;
printf("a=%s\n",a);
printf("b=%s\n",b);
int m=0,p=0;
printf("\n__________________0_____________________\n");
int n = ChangeCharToInt(b,f);
printf ("%s\n",b);
for(i = 0;i < n;i++)
printf ("%X ", f[i]);
printf("\n__________________1_____________________\n");
Utf8ToGb2312(gb2312,sizeof(gb2312),f,sizeof(f));
printf("\n__________________2_____________________\n");
printf("f[0]=%x",f[0]);
printf("f[1]=%x",f[1]);
printf("f[2]=%x\n",f[2]);
printf("gb2312[0]=%x",gb2312[0]);
printf("gb2312[1]=%x",gb2312[1]);
printf("gb2312[2]=%x",gb2312[2]);
printf("\n____________3___________________________\n");
}