PDA

View Full Version : iPhone SDK ReadLine/WriteLine capability?




Enuratique
May 16, 2008, 05:19 PM
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!



Cromulent
May 16, 2008, 05:30 PM
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 (http://www.cplusplus.com/reference/clibrary/cstdio/).