Skip to content

Instantly share code, notes, and snippets.

@sbrocket
Created November 5, 2008 22:08
Show Gist options
  • Save sbrocket/22448 to your computer and use it in GitHub Desktop.
Save sbrocket/22448 to your computer and use it in GitHub Desktop.
int cols = 2;
int rows = 3;
float levelData[cols][rows] = {5.66, 11.06, 16.49, 0, 0, 0};
NSMutableData *writeOut = [NSMutableData dataWithCapacity:cols*rows*sizeof(float)];
for (int i=0; i < cols; ++i)
[writeOut appendBytes:(void*)levelData[i] length:rows];
[writeOut writeToFile:somePath atomically:YES];
NSData *readIn = [NSData dataWithContentsOfFile:somePath];
float** newArray = (float**)malloc(cols*sizeof(float*));
for (int col=0; col < cols; ++col)
newArray[col] = (float*)malloc(rows*sizeof(float));
for (int col=0; col < cols; ++col)
for (int row=0; row < rows; ++row)
newArray[col][row] = ((float*)readIn.bytes)[col*rows+row];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment