我嘗試在iPhone應用程序中使用fwrite(C函數)。ios fwrite函數EXC_BAD_ACCESS
由於自定義的原因,我不想使用writeToFile但是fwrite C函數。
我didFinishLaunchingWithOptions寫了這個代碼功能:
FILE *p = NULL;
NSString *file= [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Hello.txt"];
char buffer[80] = "Hello World";
p = fopen([file UTF8string], "w");
if (p!=NULL) {
fwrite(buffer, strlen(buffer), 1, p);
fclose(p);
}
,但我得到的錯誤EXC_BAD_ACCESS在fwrite的功能。
任何幫助?
檢查'fopen()'的返回值:無法打開文件時返回'NULL'。 – hmjd 2012-07-23 09:08:22
我檢查它,它與NULL不同。我用代碼編輯我的帖子。 – TheFrancisOne 2012-07-23 09:10:55
這個問題可能是愚蠢的,但是......爲什麼你不使用標準的'NSFileManager'或者使用'-writeToFile:atomically:encoding:error:'或'-writeToURL:atomically:encoding:error:'' NSString'對象...?不能保證你有權在iPhone上使用'fwrite()'函數將文件寫入沙盒中...... – holex 2012-07-23 09:12:55