主题:VC++如何实现从字库中显示字符串呢?
从网上下了个程序,但是只能显示一个汉字,我在想怎么改动才能显示字符串呢如“我是水水”??现谢谢各位大侠了!!!程序如下:
#include <stdio.h>
#include <stdlib.h>
int main()
{
unsigned char incode[3]="臧"; // 要读出的汉字,GB编码
unsigned char qh = 0, wh = 0;
unsigned long offset = 0;
char mat[16][2] = {0};
FILE *HZK = 0;
int i,j,k;
//每个汉字,占两个字节, 取其区位号
qh = incode[0] - 0xa0; //获得区码
wh = incode[1] - 0xa0; //获得位码
offset = (94*(qh-1)+(wh-1))*32; //得到偏移位置
if((HZK=fopen("hzk16", "rb")) == NULL)
{
printf("Can't Open hzk16\n");
getchar();
return 0;
}
fseek(HZK, offset, SEEK_SET);
fread(mat, 32, 1, HZK);
fclose(HZK);
//显示
for(i=0; i<16; i++)
{
for(j=0; j<2; j++)
{
for(k=0; k<8; k++)
{
if(mat[i][j] & (0x80>>k))
{//测试为1的位则显示
printf("%c",'#');
}
else
{
printf("%c",'-');
}
}
}
printf("\n");
}
getchar();
return 1;
}
#include <stdio.h>
#include <stdlib.h>
int main()
{
unsigned char incode[3]="臧"; // 要读出的汉字,GB编码
unsigned char qh = 0, wh = 0;
unsigned long offset = 0;
char mat[16][2] = {0};
FILE *HZK = 0;
int i,j,k;
//每个汉字,占两个字节, 取其区位号
qh = incode[0] - 0xa0; //获得区码
wh = incode[1] - 0xa0; //获得位码
offset = (94*(qh-1)+(wh-1))*32; //得到偏移位置
if((HZK=fopen("hzk16", "rb")) == NULL)
{
printf("Can't Open hzk16\n");
getchar();
return 0;
}
fseek(HZK, offset, SEEK_SET);
fread(mat, 32, 1, HZK);
fclose(HZK);
//显示
for(i=0; i<16; i++)
{
for(j=0; j<2; j++)
{
for(k=0; k<8; k++)
{
if(mat[i][j] & (0x80>>k))
{//测试为1的位则显示
printf("%c",'#');
}
else
{
printf("%c",'-');
}
}
}
printf("\n");
}
getchar();
return 1;
}