On Aug 17, 2008, at 12:07 AM, FTB Accounts wrote:

Here is the current code I am running:

This code has many fundamental errors. I think you need to review the basics of the C language first, then of Objective-C. You have to walk before you can run.

You say that you're not getting any errors or warnings when you build this, but that can't be. You would definitely get warnings for this code.

/* START CODE */

#import <Cocoa/Cocoa.h>

int main(int argc, char *argv[])
{

        NSData *fname = "file:///Users/cknorr/mytest/MYTEST/data.txt";

You are initializing a variable of type NSData* (pointer to NSData). However, the right-hand side is not an NSData*, it's a C-style string, which is a character array (char* or char[]). These are not compatible. It's certainly not meaningful. Any attempt to use the fname variable as though it were a pointer to an NSData object would fail, because it doesn't actually contain a valid pointer to an NSData object.

        NSFileHandle *fh=[NSFileHandle fileHandleForWritingAtPath:fname];

Even if fname did contain a valid pointer to an NSData object, the above would not be correct. The +fileHandleForWritingAtPath: method of NSFileHandle expects a pointer to an NSString object as its argument, but that's not what you're providing.

Note that a pointer to a C-style string (character array), which is what's in fname, is also _not_ a valid pointer to an NSString object. They are two completely different ways of representing strings and are not directly interchangeable.

        [fh writeData:@"THIS IS A TEST"];

The -writeData: method of NSFileHandle expects a pointer to an NSData object. However, what you're passing here is a pointer to an NSString object. Again, this can't work.


        [fh closeFile];
        
   return NSApplicationMain(argc,  (const char **) argv);
}

Regards,
Ken

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to