Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
July 23, 2017, 03:39:53 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register Chat  
Pages: [1]   Go Down
  Print  
Author Topic: Closing the terminal's output in exercise 16.7?  (Read 1353 times)
dharma
Newbie
*
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 )
Logged
skochan
Administrator
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.

Cheers,

Steve
Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

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 ゥ 2009 classroomM.com. All rights reserved.