Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
June 27, 2017, 01:40:35 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: Attempt at exercise 7  (Read 1236 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:  

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.