rhnlogic wrote:
> Michael Ash wrote:
>> halt wrote:
>> > Thanks for your help but this is not exactly what I'm looking for. I'm
>> > looking for what is considered the normal approach in Cocoa to read a
>> > file one line at a time. I don't want to read a 100MB file completely
>> > into some data structure (NSData, NString or memory-mapping) just to
>> > process it line by line. It would be a waste of memory.
>> >
>> > Is there no Cocoa equivalent of fgets() or getline() which both read
>> > only one line of text from a file (stream) ?
>>
>> Why bother with "equivalents" when you can just use the real thing?
>> Objective-C is a superset of C, so you can just use fgets() and such
>> directly.
>
> This still requires some helper functions to coerce NSFile objects
> into posix paths or FILE pointers that fopen or fgets accepts.
Not at all. Just as you can use fgets(), you can also use things such as
fopen().
If you really need to bridge it, though, it's not terribly hard.
[fileHandle fileDescriptor], dup(), then fdopen() and you have a FILE *.
--
Michael Ash
Rogue Amoeba Software