I am Working on some bitmap fonts.
The idea here is that i am given 2 files
input.txt and font .txt.
I have to read a string from input.txt file and transform it using the font.txt and print the corresponding output to another file output.txt.
each character in font.txt is represented by a grid of 16×8. e.g.:
"A"=
0x00,
0x00,
0x10,
0x38,
0x6c,
0xc6,
0xc6,
0xfe,
0xc6,
0xc6,
0xc6,
0xc6,
0x00,
0x00,
0x00
0x00
Can Someone please Just give me an idea how to load the above format stored in a file into a data structure.
Take a look at this SO solution to see how to read line by line in c.
I’m assuming you work with ASCII and your array size is constant. You can simply check for the
"at the beginning of each line, in which case you can assume it’s an identifier for your letter, else you read the values line by line into the 16×8 array, dropping the , at the end if there is one.Checking for the
"can simply be done by a direct comparison since it’s an ascii character.Getting the letters could be done the same way:
You could also use
scanfto parse your line formatted. Also if you have to possibility to work in C++, it will make your life a lot easier since you’ll have access to higher level methods.