Amazon.com Widgets Closing the terminal's output in exercise 16.7?
Welcome, Guest. Please login or register.
Did you miss your activation email?
November 28, 2014, 11:07:20 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
Print
Author Topic: Closing the terminal's output in exercise 16.7? (Read 967 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:



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.