Objective
The extension of a file name can lie; the content cannot. Many formats start with fixed bytes (a magic number) that identify them.
Instructions
- The first line has the number
nof files; then one file name per line (they exist in the working folder). - Read the first 8 bytes of each one and show
name: type, where the type isPNG(89 50 4E 47 0D 0A 1A 0A),GIF("GIF8"),PDF("%PDF"),ZIP("PK\x03\x04"),JPEG(FF D8 FF) orunknownif it matches none.
2
foto.dat
doc.txt
foto.dat: PNG
doc.txt: unknown
Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.
Start exercise