Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Stack Overflow challenge!

Name: Anonymous 2010-08-21 20:20

1. Create a new text file called "fileio.txt"
2. Write the first line "hello" to the text file.
3. Append the second line "world" to the text file.
4. Read the second line "world" into an input string.
5. Print the input string to the console.

Name: Anonymous 2010-08-22 1:57

>>7

Maybe this is totally kludgy; I'm a newbie Haskell programmer. Anyway...

import System.IO

main :: IO ()
main = do
    soc <- openFile "fileio.txt" ReadWriteMode
    hPutStrLn soc "Hello"
    pos <- hTell soc
    hPutStrLn soc "World"
    hSeek soc AbsoluteSeek pos
    inpStr <- hGetLine soc
    hClose soc
    putStrLn inpStr

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List