我正在将这个Python代码从PDFMiner复制到objective-c:
(name, tsum, offset, length) = struct.unpack('>4sLLL', fp.read(16))
这就是我所拥有的:
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;
正确读取名称,但错误地读取了tsum,offset和length。 知道为什么这可能不起作用吗?
答案 0 :(得分:1)
我怀疑有填充字节,但我不知道在哪里。 L代表无符号长,所以我怀疑这是问题