用TC2.0显示汉字不知道为啥结果与预期不符


#include<stdlib.h>
#include<graphics.h>
#include<stdio.h>
#define S 16
#define HZK "c:\\TC20\\hzk16f"
void dispzh(int x,int y,char *p,int color)
{
FILE *fp;
int i,j;
char qh,wh;
long offset;
char butter[S*S/8];
char mask[]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
if((fp=fopen(HZK,"rb"))==NULL)
printf("1"); 
while(*p!='\0')
{
qh=*p-0xa0;
p++;
wh=*p-0xa0;
p++;
offset=((qh-1)*94+wh-1)*S*S/8;
fseek(fp,offset,0);
fread(butter,S*S/8,1,fp);
for(i=0;i<S*S/8;i++)
{
for(j=0;j<8;j++)
if((butter[i]&mask[j])!=0)
putpixel(x+(i%(S/8))*8+j,y+i*8/S,color);
}
x+=S+5;
}
fclose(fp);
}
int main()
{
char * p="你好";
int gdriver=DETECT,gmode;
initgraph(&gdriver,&gmode,"");
cleardevice();
dispzh(320,240,p,RED);
getch();
closegraph();
return 0;
}

运行结果

img

希望采纳
坐标计算错误。在显示点阵数据时:

for(i=0;i<S*S/8;i++)  
{  
    for(j=0;j<8;j++)  
    if((butter[i]&mask[j])!=0)  
    putpixel(x+(i%(S/8))*8+j,y+i*8/S,color);  
}

仅供参考:

#include <mem.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <graphics.h>
const unsigned char bit[8]={128,64,32,16,8,4,2,1};
//--------------------------------------------------------
void dis(xoff,code)
    unsigned int xoff,code;
{
    unsigned char *buffer;
    FILE *hzk;
    unsigned long offset;
    unsigned int q,w;
    int x,y,width;

    buffer=calloc(32,1);
    if ((code&0xFF00)!=0) {
        w=(code&0x00FF)-0xA1;
        q=((code>>8)&0x00FF)-0xA1;
        offset=q*0x5E+w;
        offset*=32;
        if ((hzk=fopen("HZK16","rb"))==NULL) {
            closegraph();
            printf("Can not open HZK16\r\n");
            exit(1);
        }
        fseek(hzk,offset,SEEK_SET);
        fread(buffer,1,32,hzk);
        fclose(hzk);
        width=2;
    }
    else {
        if ((hzk=fopen("ASC16","rb"))==NULL) {
            closegraph();
            printf("Can not open ASC16\r\n");
            exit(1);
        }
        offset=code*16;
        fseek(hzk,offset,SEEK_SET);
        fread(buffer,1,16,hzk);
        fclose(hzk);
        width=1;
    }
    for (y=0;y<16;y++) for (x=0;x<8*width;x++) {
        if (buffer[y*width+x/8]&bit[x%8]) putpixel(xoff+x,y,15);
    }
    free(buffer);
}
//--------------------------------------------------------
void display(p)
    unsigned char *p;
{

  int i;
  unsigned int qw;

  i=0;
  while (1) {
    if (p[i]==0x0D||p[i]==0x1A) break;
    if (p[i]>0xA0) {
        qw=((unsigned int)p[i]<<8)|((unsigned int)p[i+1]&0x00FF);
        dis(8*i,qw);
        i+=2;
    }
    else {
        qw=(unsigned int)p[i]&0x00FF;
        dis(8*i,qw);
        i++;
    }
  }

}
//--------------------------------------------------------
void main()
{
    int gdriver = DETECT, gmode, errorcode;
    long fl;
    FILE *hz;
    unsigned char *p;

    initgraph(&gdriver, &gmode, "c:\\borlandc\\bgi");
    errorcode = graphresult();
    if (errorcode != grOk) {
       printf("Graphics error: %s\n", grapherrormsg(errorcode));
       exit(1);
    }
    hz=fopen("hz","rb");
    fseek(hz,0,SEEK_END);
    fl=ftell(hz);
    p=calloc((int)fl,sizeof(unsigned char));
    rewind(hz);
    fread(p,1,(int)fl,hz);
    fclose(hz);
    display(p);
    free(p);
    getch();
    closegraph();
}


不知道你这个问题是否已经解决, 如果还没有解决的话:

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^