views:

51

answers:

1

Hello,

I apologize in advance if this has been addressed, but I have not found a specific answer as of yet.

First, I am trying to use a C library in an iPhone/Cocoa touch app. It compiles fine as a plain C project and as a plain Foundation project (using X-code). My problems is this: The library uses a dictionary file which is called directly using fopen(). My question is how can that file be accessed on an iPhone from a C library which does not or cannot use Objective-C/SDK routines. I'm assuming that there is a way...somehow.

Thanks!

A: 

Hello,

I think fopen is ok. But XCode put all resource files into the root directory. So maybe you should rewrite the library to open the file from the root.

Other solution is to create "folder reference" with "Add to project" menu. This way I think the whole folder will be copied to the app bundle.

Adam Wallner
I guess that would be my question. Exactly how do i access that folder from C. What would be the file path, less the actual filename of course? To my understanding,root cannot be accessed. And if I do put it in the resource folder...again, how can it be accessed from the C library? Thanks!
fulltone
I used this in a c++ project: NSString* str = [[NSBundle mainBundle] pathForResource:@"file" ofType:@"ext"]; char cstr[512] = {0}; [str getCString:cstr maxLength:512 encoding:NSASCIIStringEncoding]; loadFileC(cstr);
Adam Wallner
So first you need to get your app's root folder and you should be able to open your files from that.
Adam Wallner
I tried something similar to that earlier today but couldn't get it to work. Any suggestion on how that could be called from a C file directly?
fulltone
Ok, I think I have it figured out with the simulator.
fulltone
Fulltone can you post the code for the way you tried doing it? Perhaps we can help if we know what you did exactly
twerdster
Thanks Adam. Your suggestion's pointed me in the right direction. I will post the results once I verify it works on both the simulator and ipad/phone. So far, so good.
fulltone
Aaron, basically what i am doing is using two C libraries. And calling the C functions from Objective-C. The C libraries use external data files that are being called directly from those libraries and not associated with My Objective-C code directly. So my issue was basically file paths on the iPhone/Simulator...etc. I am still noob-ish. I will post the result...soon. But so far it is working on the Simulator. Thanks!
fulltone
I'm glad you were able to figure it out. I have similar problems some weeks ago. I am new at iPhone as well.
Adam Wallner