• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
float Array to NSData conversion
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: float Array to NSData conversion
      • From: Chris Suter <email@hidden>
  • Prev by Date: AdditionalEventParamDescriptor odoc
  • Next by Date: Re: float Array to NSData conversion
  • Previous by thread: Re: AdditionalEventParamDescriptor odoc
  • Next by thread: Re: float Array to NSData conversion
  • Index(es):
    • Date
    • Thread