发信人: proust()
整理人: wenbobo(2002-12-27 15:50:04), 站内信件
|
各位高手,请教在BORLANDC C++3.1中如何同时读取汉字与ASC码?
最好有源程序。
例如:如何读取“你好1998,希望”
请发:[email protected]
-- ※ 来源:.月光软件站 http://www.moon-soft.com.[FROM: 203.93.7.52] 发信人: xiaomiao (楚狂人), 信区: C 标 题: Re: 请教汉字与ASC码同时读取的C语言程序 发信站: 网易虚拟社区 (Thu Jul 15 10:29:11 1999), 站内信件
【 在 proust (proust) 的大作中提到: 】
: 各位高手,请教在BORLANDC C++3.1中如何同时读取汉字与ASC码?
: 最好有源程序。
: 例如:如何读取“你好1998,希望”
: 请发:[email protected]
: .......
给你一个老程序,在BC++3.1下调试通过,要用到UCDOS的16点阵字库
HZK16.不过为了速度,最好用直接写屏的算法.
/* Display Chinese string in BGI mode */
/* Using the UCDOS HZK16 Chinese character library */
#include <graphics.h>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
int outxyhz(int x,int y,char *p,int color);
int disp_hz(int left,int top,unsigned char byte1,
unsigned char byte2,int color);
void main()
{
int gdrive=VGA,gmode=VGAHI;
initgraph(&gdrive,&gmode,"\\bc31\\bgi");
setbkcolor(BLUE);
cleardevice();
outxyhz(200,100,"计算机软件开发",WHITE);
outxyhz(100,164,"Press any key to exit!(按任意键退出)",LIGHTRED);
outxyhz(100,200,"程序设计 XiaoMiao 1996.9. All rights not reserved." ,YELLOW);
outxyhz(100,225,"Please distribute this program freely.",CYAN);
getch();
closegraph();
}
/* function to show a text string with Chinese and English */
int outxyhz(int x,int y,char *p,int color)
{
int oldcolor;
char q[2];
oldcolor=getcolor(); /* keep the current color setting */
setcolor(color);
while(*p)
{
if(((unsigned char)*p>=0xa1&&(unsigned char)*p<=0xfe)
&&((unsigned char)*(p+1)>=0xa1&&(unsigned char)*(p+1)<=0xfe))
{
if((x+16-1)>getmaxx()||(y+16-1)>getmaxy())
return 0;
disp_hz(x,y,*p,*(p+1),color);
p+=2;
x+=16+2;
}
else
{
moveto(x,y);
*q=*p;
*(q+1)='\0';
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
outtextxy(x,y+4,q);
x+=8+1;
p++;
}
}
setcolor(oldcolor);
return 1;
}
/* function to display a chinese character; Using HZK16 in UCDOS */
int disp_hz(int left,int top,unsigned char byte1,
unsigned char byte2,int color)
{
FILE *fp;
unsigned char buf[32];
unsigned char mark;
long p;
int x,y,i,j;
// int quma,weima;
fp=fopen("c:\\ucdos\\hzk16","rb"); // Using UCDOS 16*16 LIB
if(fp==NULL)
{
closegraph();
puts("Cannot open HZK16 file!\n");
exit(1);
}
if((byte1>=0xa1&&byte1<=0xfe)
&&(byte2>=0xa1&&byte2<=0xfe))
{
// quma=byte1-0xa0;
// weima=byte2-0xa0;
p=(byte1-0xa1)*94+byte2-0xa1;
p*=32;
fseek(fp,(long)p,SEEK_SET);
fread(buf,sizeof(unsigned char),32,fp);
for(i=0,y=top;i<32;i+=2,y++)
for(mark=0x80,j=0;mark>0;mark=mark>>1,j++)
{
if((buf[i]&mark)!=0)
putpixel(left+j,y,color);
if((buf[i+1]&mark)!=0)
putpixel(left+j+8,y,color);
}
}
fclose(fp);
return 1;
}
-- Life it seems to fade away,
Drifting further every day...
---我本楚狂人,凤歌笑孔丘---
※ 来源:.月光软件站 http://www.moon-soft.com.[FROM: 202.103.100.243] 发信人: undir (z), 信区: C 标 题: Re: 请教汉字与ASC码同时读取的C语言程序 发信站: 网易虚拟社区 (Thu Jul 15 10:31:08 1999), 站内信件
【 在 proust (proust) 的大作中提到: 】
: 各位高手,请教在BORLANDC C++3.1中如何同时读取汉字与ASC码?
: 最好有源程序。
: 例如:如何读取“你好1998,希望”
: 请发:[email protected]
: .......
又汉字特点可知其所对应的ASCII大于128
故可判断:
例判断一行有几个汉字:
void main()
{
char c;int total(0);
cout<<"please input a line"<<endl;
do
{
cint>>c;
if(chr(c)>128)
{ cint>>c;
if(chr(c)>128) //因为汉字为双字节故要判断两位
total++;
}
while(c==null);
cout<<\n"其中汉字为"<<total<<"个"<<endl;
}
//此程序需要汉字系统支持
bye------------------
[email protected]
-- ※ 来源:.月光软件站 http://www.moon-soft.com.[FROM: 202.101.168.157]
|
|