Reputation: 159
I’m copying this python code from PDFMiner into objective-c:
(name, tsum, offset, length) = struct.unpack('>4sLLL', fp.read(16))
This is what I have:
unsigned char characters[5];
[stream getBytes:characters range:NSMakeRange(position, 4)];
position+=4;
characters[4] = 0;
NSString* name = [NSString stringWithFormat:@"%s", characters];
unsigned long tsum;
[stream getBytes:&tsum range:NSMakeRange(position, 4)];
position+=4;
unsigned long offset;
[stream getBytes:&offset range:NSMakeRange(position, 4)];
position+=4;
unsigned long length;
[stream getBytes:&length range:NSMakeRange(position, 4)];
position+=4;
The name is read correctly, but the tsum, offset, and length are read incorrectly. Any idea why this might not work?
Upvotes: 0
Views: 82
Reputation: 56
I suspect there's padding bytes, but I'm not sure where. L stands for unsigned long so I doubt that's the problem
Upvotes: 1