c语言实现判断汉字

来源:互联网 发布:手机淘宝免费使用在哪 编辑:程序博客网 时间:2024/06/02 05:18

#include <windows.h>
int IsGB(PTSTR pText)
{
 unsigned char sqChar[20];
 sqChar[0]=*pText;
 if (sqChar[0]>=0xa1)
  if (sqChar[0]==0xa3)
   return 1;//全角字符
  else
   return 2;//汉字
 else
  return 0;//英文、数字、英文标点
}

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
 static TCHAR szText[] = {TEXT ("i服,了。uy")} ;
 PTSTR pText;
 int i;

 
 pText=szText;
 while (*pText != '/0')
 {
  i=IsGB(pText);
  switch(i)
  {
  case 0:
   pText++;
   MessageBox (NULL, TEXT ("发现数字、英文字符或英文标点"), TEXT ("Hello"), 0);
   break;
  case 1:
   pText++;
   pText++;
   MessageBox (NULL, TEXT ("发现全角字符"), TEXT ("Hello"), 0);
   break;
  case 2:
   pText++;
   pText++;
   MessageBox (NULL, TEXT ("发现汉字"), TEXT ("Hello"), 0);
   break;
  }
 }
 return 0 ;
}