Hi!,
I use the following code to open a binary file:
But sometimes, not very often, the functions returns -1.
Is there any problem in this code, or a reason why only sometimes this function doesn't find the file?, although the file is present.
Any help would be appreciated.
Thanks.
I use the following code to open a binary file:
Code:
const char* fileName = "myFile.bin";
FILE* file = NULL;
const char* buffer;
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
NSString *path = [NSString stringWithUTF8String:fileName];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
path = [documentsDirectory stringByAppendingPathComponent:path];
if (path != nil)
buffer = [path UTF8String];
[pool release];
file = fopen(buffer, "rb");
if (!file)
return -1;
//Do fread stuff here
fclose(file);
return 0;
But sometimes, not very often, the functions returns -1.
Is there any problem in this code, or a reason why only sometimes this function doesn't find the file?, although the file is present.
Any help would be appreciated.
Thanks.
Last edited: