⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 utf8tounicode.c

📁 这个文件是为了实现GSM发送短信的一部分代码
💻 C
字号:
/*	          文 件 名:Utf8ToUnicode.c    作    者:丁宏伟    创建时间:2008年10月    修改时间:2008年11月26日*/#include <stdio.h>#include <stdlib.h>#include <string.h>#include "gsm.h"int  utf8_to_unicode(char *unicode,char *utf8,int n){	char buf[3]={0};		char buf1[3]={0};	char utf81[256]={0};		int i,j=0,k=0;	int byte1=128; 	//1 byte 1000 0000;	int value1=0;	int byte2=224;	//2 byte 1110 0000用于与utf8[i]与保留前4位;	int value2=192;	int byte3=240;	//3 byte 1111 0000; 	int value3=224;	if(n>128) n=128;	for(i=0;i<n;i++){		if((utf8[i]&byte1) == value1){			unicode[j]='0';			unicode[++j]='0';			memset(buf,0,3);			itoa(utf8[i],buf,3);			unicode[++j]=buf[0];			unicode[++j]=buf[1];			j++;			memset(buf,0,3);			memset(buf1,0,3);		}		if((utf8[i]&byte2) == value2){//判断是否是两个字节			memset(buf,0,3);			memset(buf1,0,3);			buf[0]=(utf8[i]&0x1f)<<3;			buf[0]=((utf8[++i]&0x3f)<<2)>>5;			itoa(buf[0],buf1,3);			unicode[j]=buf1[0];			unicode[++j]=buf1[1];			buf[1]=((utf8[++i]&0x3f)<<5);			itoa(buf[1],buf1,3);				//	sprintf(buf1,"%x",buf[0]);			unicode[++j]=buf1[0];			unicode[++j]=buf1[1];			//	sprintf(buf1,"%x",buf[1]);			j++;			memset(buf,0,3);			memset(buf1,0,3);		}		if((utf8[i] & byte3) == value3){			buf[0]=(utf8[i] & 0x1f)<<4;			buf[0]|=((utf8[++i]&0x3f)<<2)>>4;			itoa(buf[0],buf1,3);			unicode[j]=buf1[0];			unicode[++j]=buf1[1];			buf[1]|=(utf8[i]&0x3f)<<6;					buf[1]|=((utf8[++i]&0x3f)<<2)>>2;			itoa(buf[1],buf1,3);			unicode[++j]=buf1[0];			unicode[++j]=buf1[1];			j++;			memset(buf,0,3);			memset(buf1,0,3);		}	}	if(j==0){		for(i=0;i<n;i++){			memset(buf,0,3);			memset(buf1,0,3);			itoa(utf8[i],buf,3);			unicode[k++]=buf[0];				if(k==1)				printf("unicode %c ",unicode[0]);			else	printf("unicode %c ",unicode[k]);			unicode[k++]=buf[1];				printf("unicode %c ",unicode[k]);		}		j=k;	}	return j;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -