fprintf 导致设备崩溃但模拟器不崩溃?
我有一个运行 iOS 4.2.1 的 iPod touch 和一个运行 iOS 4.2 的模拟器。在模拟器中,我的代码运行得很好,但在设备上,它崩溃了。
有问题的代码是:
FILE *file = fopen([[@"niplot/" stringByAppendingString:text_field.text] fileSystemRepresentation], "w");
...
fprintf(file, "%s", [print_str UTF8String]); //crash occurs here, EXC BAD ACCESS
...
fclose(file);
它是否与不存在的文件或文件夹有关?在这种情况下,模拟器为我创建了它们。我尝试在设备上手动创建文件和文件夹,但我不确定如何创建。另外,我尝试了带或不带 .txt 扩展名的文件名。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是 文件保存/加载/删除的一些示例。
Here's some examples of file save/load/delete.