Welcome, Guest. Please login or register.
Did you miss your activation email?
May 27, 2017, 11:37:09 PM
Home Help Search chat Login Register 
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan

+ Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+ Old Stuff
| |-+ Answers to Exercises
| | |-+ Chapter 16 (Moderator: sgg_admin)
| | | |-+ Closing the terminal's output in exercise 16.7?
Pages: [1] Go Down
Author Topic: Closing the terminal's output in exercise 16.7? (Read 1335 times)
Posts: 23

on: March 24, 2010, 01:32:47 AM

So, my question is, in the code I have:
Code: (Objective-C)
#import <Foundation/Foundation.h>

#define kBufSize 128

int main (int argc, const char * argv[]) {

NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSFileHandle *inFile, *outFile;
NSData *buffer;

inFile = [NSFileHandle fileHandleForReadingAtPath:@"testfile"];

if (inFile == nil)
NSLog(@"Open of testfile for reading failed!");
return 1;

outFile = [NSFileHandle fileHandleWithStandardOutput];

buffer = [inFile readDataOfLength: kBufSize];

while (buffer.length != 0) {
[outFile writeData: buffer];
(buffer = [inFile readDataOfLength: kBufSize]);

[inFile closeFile];
[outFile closeFile];

[pool drain];
return 0;}

Do we need to close outFile, since it isn't really a file but the terminal's output? (I should call it outToTerminal or something, I know Wink )
Hero Member
Posts: 3114

Reply #1 on: March 24, 2010, 11:25:56 AM

It will be closed when the application terminates.  It's a good habit to get into anyway.   If it were a file, closing it would flush out any data pending to be written to the file.


Pages: [1] Go Up
Jump to:

Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents (c) 2009 classroomM.com. All rights reserved.