I am working on some bitmap fonts. The idea here is that I am given two files (input.txt and font.txt). I have to read a string from input.txt and transform it using the contents of font.txt and then print the corresponding output to another file called output.txt. Each character in font.txt is represented by a grid of 16×8.
I just implement a simple [rogram to transform a single Char A using to bitmap as below. Can someone please help me to reduce the code.
Thank You.
int main()
{
unsigned int arr[]=
{
0x00,0x00,0x10,0x38,
0x6c,0xc6,0xc6,0xfe,
0xc6,0xc6,0xc6,0xc6,
0x00,0x00,0x00,0x00
};
int i,k,j;
int bin[8];
int c=7;
for(i=0;i<16;++i)
{
bin[0]=arr[i]>>7;
bin[1]=(arr[i]>>6)&1;
bin[2]=(arr[i]>>5)&1;
bin[3]=(arr[i]>>4)&1;
bin[4]=(arr[i]>>3)&1;
bin[5]=(arr[i]>>2)&1;
bin[6]=(arr[i]>>1)&1;
bin[7]=arr[i]&1;
k=0;
for(j=0;j<4;j++){
if(bin[k]==0 && bin[k+1]==0)
{
printf("..");
}
else if(bin[k]==0 && bin[k+1]==0)
{
printf(".C");
}
else if(bin[k]==0 && bin[k+1]==0)
{
printf("C.");
}
else
{
printf("AA");
}
k=k+2;
}
printf("\n");
}
}
OUTPUT:
........
........
..AA....
..AAAA..
AAAAAA..
AA..AAAA
AA..AAAA
AAAAAAAA
AA..AAAA
AA..AAAA
AA..AAAA
AA..AAAA
........
........
........
........
This produces the same output that you have, but I am ignoring the logic for “.C” and “C.” since your codes does as well. 😉