/* Filename: ChinesetoUnicode code by:1jjk Email:lingjiujianke@gmail.com Compile: gcc -Wall -O2 -g ChinesetoUnicode.c -o ChinesetoUnicode */
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <assert.h> #include <locale.h>
int main() { FILE *fp; int ret=-1; char str[1024]={0,}; wchar_t array[1024]={0,}; setlocale(LC_ALL, "zh_CN.GBK");
/*open file*/ if((fp=fopen("/root/smsconfig.txt","r"))==NULL) { printf("error\n"); } fscanf(fp,"%s",str); printf("%s\n",str); fclose(fp); assert(str); assert(array);
/*from chinese to Unicode*/ if((ret=mbstowcs(array, str, strlen(str)))==-1) { printf("error\n"); } int i = 0; char buf[5] = {0,}; for(i=0; i<ret; ++i) { printf("%04X", (int)(array[i]&0xFFFF)); }
/*from Unicode to Chinese*/ if((ret=wcstombs(str,array, strlen(array)))==-1) { printf("error\n"); }
printf("\n %s \n",str); return 0; }
|