以UTF8interrotation函数sqlite3提供ANSI
它必须在使用sqlite3使用方法:
字符串= …; / /被转换为ANSI或utf8字符串
char * = null;保存由内存指针函数分配的内存,不需要内存缓冲区
它转换为UTF-8:to_utf8(src,dst);
它转换为ANSI:to_gb(src,dst);
返回值:零失败,非零成功。
注意:如果操作成功,您需要手动释放函数中分配的空间:
复制代码代码如下所示:
如果(DST)
{
免费(DST);
DST =空;
}
代码:
复制代码代码如下所示:
#包括
#包括int to_utf8(char * PSRC,char * ppdst)
{
int返回,ret2;
wchar_t * PWS = null;
char * PUTF = null;
ret = MultiByteToWideChar(cp_acp,0,1,零,PSRC,0);
如果(RET < = 0){
* ppdst = null;
返回0;
}
PWS =(wchar_t *)malloc(RET×2);
如果(!PWS){
* ppdst = null;
返回0;
}
MultiByteToWideChar(cp_acp,0准,1,PWS,RET);
ret2 = WideCharToMultiByte这两个函数(cp_utf8,0,PWS,1,零,0,零,零);
如果(ret2 <= 0){
免费(PWS);
返回0;
}
PUTF =(char *)malloc(ret2);
如果(!Putf){
免费(PWS);
返回0;
}
如果(WideCharToMultiByte(cp_utf8,0,PWS,RET,PUTF,ret2,null,null)){
* ppdst = PUTF;
免费(PWS);
返回1;
其他{ }
免费(PWS);
免费(PUTF);
* ppdst = null;
返回0;
}
}
国际to_gb(char * PSRC,char * ppdst)
{
int返回,ret2;
wchar_t * PWS = null;
char * PGB = null;
ret = MultiByteToWideChar(cp_utf8,0,1,零,PSRC,0);
如果(RET < = 0){
* ppdst = null;
返回0;
}
PWS =(wchar_t *)malloc(RET×2);
如果(!PWS){
* ppdst = null;
返回0;
}
MultiByteToWideChar(cp_utf8,0准,1,PWS,RET);
ret2 = WideCharToMultiByte这两个函数(cp_acp,0,PWS,1,零,0,零,零);
如果(ret2 <= 0){
免费(PWS);
返回0;
}
PGB =(char *)malloc(ret2);
如果(!PGB){
免费(PWS);
* ppdst = null;
返回0;
}
如果(WideCharToMultiByte(cp_acp,0,PWS,1,好,ret2,null,null)){
* ppdst =好;
免费(PWS);
返回1;
} { *其他ppdst = 0;
免费(PGB);
免费(PWS);
返回0;
}
}
女孩不要哭