Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Enuratique

macrumors 6502
Original poster
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!
 
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.