Homebrew Writte to file?(Devkitpro)

Foxi4

Endless Trash
Global Moderator
Joined
Sep 13, 2009
Messages
30,824
Trophies
3
Location
Gaming Grotto
XP
29,818
Country
Poland
Hello,
can anyone tell me how i can writte something to a file using devkitpro (and c)?
Thanks
1. Initialize fatlib and create a FILE variable.
2. Open a file
3. fwrite your buffer

Code:
#include 

fatInitDefault();

FILE* aFile;
char* buffer;

chdir("fat:/YourPath");
aFile = fopen ("aFileYouWantToCreate.Extension" , "wb" );
fwrite (buffer , 1 , sizeof(buffer) , aFile );
fclose (aFile);

EDIT: Fixed
 

Foxi4

Endless Trash
Global Moderator
Joined
Sep 13, 2009
Messages
30,824
Trophies
3
Location
Gaming Grotto
XP
29,818
Country
Poland
Thank you, but i get this error:
...../main.c:41: undefined reference to `fatDefau
ltinit'

How can i fix it?
You are correct - I made a boo boo. It was supposed to be fatInitDefault(); not the other way around, correct that and it'll work. Sorry, routine kills sometimes. ;)

Also, remember to change the makefile and #include the library if you still haven't:

Code:
Change line:

LIBS:= -lnds9

Into:

LIBS:= -lfat -lnds9

A useful read:

http://chishm.drunke...ers.com/libfat/
 

DragonRider

Well-Known Member
OP
Member
Joined
Aug 25, 2011
Messages
104
Trophies
0
Website
Visit site
XP
202
Country
Australia
hm, i still get the error :(
Fixxed!

That was my problem:
Using libfat in a project
The following assumes that you are using one of the example NDS templates.
The first step is adding libfat to the list of libraries. In the ARM9 Makefile (or the top level one if there is no specific ARM9 Makefile), look for the list of libraries. It should look like:
LIBS := -lnds9
Change this to:
LIBS := -lfat -lnds9
The order is important! Make sure that -lfat comes before -lnds9. The include directory will already be set, so you don't need to worry about this.


You was faster xD


Now it work!
Thank you
 

Foxi4

Endless Trash
Global Moderator
Joined
Sep 13, 2009
Messages
30,824
Trophies
3
Location
Gaming Grotto
XP
29,818
Country
Poland
hm, i still get the error :(
You sure you changed the line, #include'ed and written the correct code? By the way, remember that FAT doesn't work on emulators.

EDIT: Great, I'm glad I could help. :) Sorry, sometimes I completely forget about the makefile, I have one pre-prepared one and I just copy-paste it to my projects so I completely forget about that part. ;)
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
    The Real Jdbye @ The Real Jdbye: quite a tight bend on that 8pin->12pin adapter in my case, which is the worst case scenario, but...