iPhone SDK ReadLine/WriteLine capability?

Discussion in 'Mac Programming' started by Enuratique, May 16, 2008.

  1. Enuratique macrumors 6502

    Joined:
    Apr 28, 2008
    #1
    Hi all,

    I've looked high and low for functionality that is similar to System.in.readLine() [in Java] and BufferedReader.ReadLine() [in .NET] in the iPhone SDK. The closest thing I can find is NSString's withContentsOfFile. My intent is to have a text file with one word per line, but reading in the whole file (with about 20,000 words in it) into one string seems needlessly inefficient. But there's no middle ground - I would then have to use NSFileHandle and seek individual bytes until I've reached a newline character or the EOF, whichever comes first. Am I missing something? This seems like a common thing to do.

    Thanks!
     
  2. Cromulent macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #2
    You could always just do it the good old fashioned C way.

    fopen()

    fread()

    fwrite()

    fclose()

    getchar()

    fsetpos()

    fgetpos()

    fseek()

    are probably the functions that you will want to use. Simple, fast and effective. Reference here.
     

Share This Page