简体   繁体   中英

fprintf causes device to crash but not simulator?

I have an iPod touch running iOS 4.2.1, and a simulator running iOS 4.2. In the simulator, my code works just fine, but on the device, it crashes.

The code in question is:

FILE *file = fopen([[@"niplot/" stringByAppendingString:text_field.text] fileSystemRepresentation], "w");
...
fprintf(file, "%s", [print_str UTF8String]); //crash occurs here, EXC BAD ACCESS
...
fclose(file);

Could it have something to do with the file or folder not existing? The simulator created them for me in this case. I'd try to create the files and folders manually on the device, but I'm not sure how. Also, I've tried the file names with and without a.txt extension.

Here's some examples of file save/load/delete.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM