简体   繁体   English

fprintf 导致设备崩溃但不是模拟器?

[英]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.我有一个运行 iOS 4.2.1 的 iPod touch,以及一个运行 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.另外,我尝试了带有和不带有 a.txt 扩展名的文件名。

Here's some examples of file save/load/delete.这是文件保存/加载/删除的一些示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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