I have been given a static library to work with that accepts arguments as a space delimited char.
Method in library
int saveFile(char* param);
I am passing it the Documents file path to save to
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
std::string str = [documentsDirectory cStringUsingEncoding:[NSString defaultCStringEncoding]];
const char * filePath = str.c_str();
char pa[1024];
pa[0] = 0;
strcat(pa, filePath);
saveFile(pa);
My problem is that the IOS file path has spaces in it and this causes the library to split the path in those places. I have tried escaping the spaces with a “\” and of course, placing the path in quotes does not work in this instance. For example below…
/Users/bigbadowl/Library/Application Support/iPhone Simulator/5.1/Applications/649D2EEB-8C88-42C7-9A74-21629570B1D0/Documents
Would be split in to
/Users/bigbadowl/Library/Application
Support/iPhone
Simulator/5.1/Applications/649D2EEB-8C88-42C7-9A74-21629570B1D0/Documents
Any ideas would be appreciated.
Thanks
One solution would be replacing the spaces in the original string with an unlikely-to-be-used character (such as
#), perform the library manipulations, and then revert all the occurrences of this character back to spaces. Something along the lines of:Of course, you won’t get the desired behavior if the original string contains this character. You could always test this and select another character, so this shouldn’t be a problem, though.