fwrite resulting in empty file

334 views
Skip to first unread message

KK

unread,
Dec 4, 2009, 7:18:05 AM12/4/09
to android-ndk
Hi,

I am new to Android NDK and I am trying the following code

FILE* fp = fopen("/sdcard/test", "wb");
if(NULL == fp)
{
return -1;
}

int written = fwrite("Test", 1, 4, fp);
fflush(fp);
if(4 != written)
{
return -2;
}

fclose(fp);
return 0;

I am trying this on the emulator. My code returns 0 and the file is
created in the sdcard I have created for the emulator. But the problem
is that the file is empty. If anybody has seen this earlier, please
help me. I have an SD card of 2GB capacity.

Thanks in advance

Tobias Lindberg

unread,
Dec 7, 2009, 4:29:30 AM12/7/09
to andro...@googlegroups.com
Hi,
I Haven't tried to write to a file my self, only read wich was successful, however when
I was looking for information on how to read a file I stumbled on a thread somewhere where
someone also wanted to write to a file without success and the tip he received was to add
a <uses-permission> in the manifest-file to be able to write.

I hope this will be of help to you,
Tobias Lindberg


--

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.



Krishnakumar Ramachandran

unread,
Dec 7, 2009, 5:06:28 AM12/7/09
to andro...@googlegroups.com
Hi Tobias,

  I am already using the permission. I am reading from another file in the sd card and that is successful. Only my write seem to have a problem.

Thanks
KK
Reply all
Reply to author
Forward
0 new messages