float Array to NSData conversion
float Array to NSData conversion
- Subject: float Array to NSData conversion
- From: sheen mac <email@hidden>
- Date: Sun, 3 Dec 2006 22:39:47 -0800 (PST)
Hi All,
I created a float Array and converted it into NSData.And I saved
the file.If I open that file in the same computer it returns correct
value otherwise it returns zero.I attached the code below.
Kindly help me.
Thanks in Advance,
Sheen
#import "Controller.h"
static float *getVal=NULL;
@implementation Controller
- (id) init {
self = [super init];
if (self != nil) {
getVal = (float*)malloc(8 * sizeof(float));
getVal[0]=(float)10.0;
getVal[1]=(float)20.0;
getVal[2]=(float)30.0;
getVal[3]=(float)40.0;
getVal[4]=(float)50.0;
getVal[5]=(float)60.0;
}
return self;
}
- (IBAction)open:(id)sender
{
NSData *data=[NSData dataWithContentsOfFile:[NSHomeDirectory() stringByAppendingPathComponent:@"2.txt"]];
[data getBytes:getVal];
int i=0;
for (i=0;i<6; i++) {
NSLog(@"%f",getVal[i]);
}
}
- (IBAction)save:(id)sender
{
NSData *data=[NSData dataWithBytes:getVal length:(6*sizeof(float))];
[data writeToFile:[NSHomeDirectory() stringByAppendingPathComponent:@"2.txt"] atomically:YES];
}
@end
---------------------------------
Want to start your own business? Learn how on Yahoo! Small Business.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden