Hello there. I used the code below to read and print the bitmap file attached (bitmap.bmp), which contains the character ASCII 26 (or 1A-hexa). This special character is used by MSDOS as an end of file marker.
 
import IO
import IOExts
 
main :: IO ()
main = do
 bmFile <- openFileEx "bitmap.bmp" (BinaryMode ReadMode)
 charloop bmFile 0
 
charloop :: Handle -> Integer -> IO ()
charloop bmFile 70 = hClose bmFile
charloop bmFile n = do
   hSeek bmFile AbsoluteSeek n
   a <- hGetChar bmFile
   putStrLn [a]
   charloop bmFile (n+1)
 
This program did not stuck after reading the special character, but if you change putStrLn by putStr you will notice that a strange thing happens: after reading the special character, the program won't show any more characters. Why does it happen?
 
Thanks,
Andre Furtado

bitmap.bmp

Reply via email to