You cannot declare an array using a variable, therefore Byte byteData[len]; will not work. If you want to copy data from a pointer, you will also need memcpy (which will go through the data pointed to by the pointer and copy each byte to the specified length).
Try:
NSData *data = [NSData dataWithContentsOfFile:filePath]; NSUInteger len = [data length]; Byte *byteData = (Byte*)malloc(len); memcpy(byteData, [data bytes], len);
This code will dynamically allocate the array to the correct size (you should free(byteData) when you're done) and copy the bytes into it.
You can also use getBytes:length: as indicated by others if you want to use a fixed-length array. This avoids malloc / free, but is less extensible and more prone to buffer overflow problems, so I rarely use it.
Matt Gallagher Apr 07 '09 at 6:39 2009-04-07 06:39
source share