fopen returns NULL

1,216 views
Skip to first unread message

Oceanblue

unread,
Aug 30, 2011, 4:39:20 PM8/30/11
to android-ndk
Hi folks,

I'm trying to save a byte array to a file, but not successful.

Here is the code I tried
FILE * pFile;
pFile = fopen ( "my.bin" , "wb" );
__android_log_write(ANDROID_LOG_DEBUG, DEBUG_TAG, "opened
file");
if (NULL == pFile){
__android_log_write(ANDROID_LOG_DEBUG, DEBUG_TAG, "null
file pointer");
}
fwrite (barray , 1 , barray_size , pFile );
fclose (pFile);


I get this message in logcat:
"null file pointer"

I do have this permission in the manifest too:
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-
permission>

Any thoughts?

David Turner

unread,
Aug 30, 2011, 4:40:53 PM8/30/11
to andro...@googlegroups.com
what's the value of errno, it should tell you what's wrong.


--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.


Oceanblue

unread,
Aug 30, 2011, 4:50:38 PM8/30/11
to android-ndk
Hi David,

Thanks for quick response, as always.

errno = 30
strerror(errno) = Read-only file system

Hmmm. Wonder what I have to do to write to it.

Oceanblue

unread,
Aug 30, 2011, 5:19:34 PM8/30/11
to android-ndk
Ok, I resolved it.

I needed to use the full pathname in the fopen.
Reply all
Reply to author
Forward
0 new messages