Amazon.com Widgets Attempt at exercise 7
Welcome, Guest. Please login or register.
Did you miss your activation email?
December 22, 2014, 05:41:13 AM
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)
| | | |-+ Attempt at exercise 7
Pages: [1] Go Down
Print
Author Topic: Attempt at exercise 7 (Read 848 times)
esc
Global Moderator
Full Member
*****
Posts: 230






on: February 19, 2009, 10:32:09 AM

#import <Foundation/Foundation.h>

#define INFILE @"foo"
#define KBufSize 128

int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

    NSFileHandle *infile, *outfile;
   NSData *buffer;
   
   infile = [NSFileHandle fileHandleForReadingAtPath: INFILE];
   if ( infile == nil ) {
      printf("Open %s for reading failed!\n", [INFILE UTF8String]);
      return 1;
   }
   
   outfile = [NSFileHandle fileHandleWithStandardOutput];
   if ( outfile == nil ) {
      printf("Cannot open stdout!\n");
      return 2;
   }
   
   buffer = [infile readDataOfLength: KBufSize];
   while ( [buffer length] > 0 ) {
      [outfile writeData: buffer];
      buffer = [infile readDataOfLength: KBufSize];
   }
   
   [infile closeFile];
   [outfile closeFile];
   
    [pool drain];
    return 0;
}

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.