Amazon.com Widgets 16-6 Simple way
Welcome, Guest. Please login or register.
Did you miss your activation email?
December 17, 2014, 02:26:38 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)
| | | |-+ 16-6 Simple way
Pages: [1] Go Down
Print
Author Topic: 16-6 Simple way (Read 1236 times)
tadej5553
Full Member
***
Posts: 145


Email




on: January 21, 2010, 12:48:21 PM

main.m
Code: (Objective-C)
#import <Foundation/Foundation.h>  
#define kBuffSize 256

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; 
    } 
       
    [[NSFileManager defaultManager] createFileAtPath: @"testout" contents: nil attributes: nil]; 
       
    outFile = [NSFileHandle fileHandleForWritingAtPath: @"testout"]; 
   
    if (outFile == nil) 
    { 
        NSLog(@"open of outfile for writing failed!"); 
        return 2; 
    } 
   
    [outFile truncateFileAtOffset: 0]; 
   
    while([buffer = [inFile readDataOfLength: kBuffSize] length] != 0)
        [outFile writeData: buffer]; 
   
    [inFile closeFile]; 
    [outFile closeFile]; 
   
    NSLog(@"%@", [NSString stringWithContentsOfFile: @"testout" encoding: 
                  NSUTF8StringEncoding error: NULL]);   
   
    [pool drain]; 
    return 0; 

Logged
meevis
Newbie
*
Posts: 1






Reply #1 on: August 18, 2010, 12:23:23 PM

so what is the output supposed to be? just what is in "testfile"?
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.