63,594
社区成员




#ifndef ASKPY_H
#define ASKPY_H
char GetFirstLetter(const char *HzChar);
char *GetFirstLetters(const char *HzString);
static const unsigned char FirstLetterIndex[126][191] = { /* GBK汉字拼音首字母ASCII码表 */
{121,115,120,109,109, 99,115,100,113,108,121, 98,106,106,106,107, 99,122,104,106,
102,121,121,119,106,104,122,104,115,121,121,103,106,104,104,100,115,110,107,107,
116,109,111, 99,120,121,112,115,110,113,115,101, 99, 99,122,103,103,108,108,121,
106,109,122, 0,121,115,115,103,121,122,121,100,121,120,106,121,121,122,108,100,
119,106,114,119, 98, 98,102,116,101,120,122,104,104, 98, 99,122,115,114,102,109,
113,119,121,102, 99,119,100,122,112,121,100,100,119,121,120,106, 97,121,112,115,
102,116,122,121,106,120,120,120,122,120,110,110,120,120,122,122, 98,112,121,115,
121,122,104,109,122, 98,113, 98,122, 99,121,122, 98,120,113,115, 98,104,104,120,
103,102,109, 98,104,104,103,113, 99,120,115,116,104,108,121,103,121,109,120, 97,
108,101,108, 99, 99,120,122,114,106,115,100},
....
char GetFirstLetter(const char *HzChar)
{
/* 该函数基于GBK汉字拼音首字母表 */
unsigned char Letter;
int len=strlen(HzChar);
if(len!=2) return ' ';
Letter=FirstLetterIndex[(unsigned char)HzChar[0]-129][(unsigned char)HzChar[1]-64];
if(Letter==0) Letter=' ';
return Letter;
}
char *GetFirstLetters(const char *HzString)
{
/* 该函数基于GBK汉字拼音首字母表 */
static char strret[1024];
char hz[3];
int i=0;
int k=0;
int len=strlen(HzString);
memset(strret,0,sizeof(strret));
while(i<len)
{
memset(hz,0,sizeof(hz));
if((unsigned char)HzString[i]>128)
{
hz[0]=HzString[i++];
hz[1]=HzString[i++];
strret[k++]=GetFirstLetter(hz);
}
else
{
strret[k++]=HzString[i++];
}
}
return strret;
}