That's because your code set the index position to 5
and start writing from there, thus replacing everything from 5
onwards.
I would copy the content of the file to a variable and modify it from there as a string
.
as by the looks of it what you attempt to do is not possible
Update:
Given that what you need is to write from X offset this should do the trick
NSFileHandle *file;
NSMutableData *data;
const char *bytestring = "black dog";
data = [NSMutableData dataWithBytes:bytestring length:strlen(bytestring)];
file = [NSFileHandle fileHandleForUpdatingAtPath: @"/tmp/quickfox.txt"];
if (file == nil)
NSLog(@"Failed to open file");
[file seekToFileOffset: 10];
[file writeData: data];
[file closeFile];