gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > Possibility of reading in *.txt files by code

#132728 - phoenix23 - Thu Jun 28, 2007 11:29 pm

Hey all,
I have a question.
Is it possible to use the "fopen" function to create, edit and access *.txt files? I wish to read in from a text file and write out to it too using "libfat" or any other mechanism on the DS.

I tried to write to a text file, however, the file never got created in the first place.

Any help will be appreciated.
Thanks in advance.

#132730 - kusma - Thu Jun 28, 2007 11:49 pm

are you sure you closed the file (fclose()) before terminating the application?

#132731 - phoenix23 - Thu Jun 28, 2007 11:50 pm

Yes, I did...

#132732 - phoenix23 - Fri Jun 29, 2007 12:05 am

If someone could post a working example of creating a text file and writing info to it (using fopen,fprintf etc or any other mechanism), I'll appreciate it.

#132736 - tepples - Fri Jun 29, 2007 12:52 am

RAC reads and writes a binary file. A "text file" is just a binary file encoded in ASCII, ISO 8859-1, or UTF-8.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#132742 - HyperHacker - Fri Jun 29, 2007 1:41 am

Code:
FILE* FP = fopen("test.txt", "wt");
if(!FP) return 0; //file couldn't be opened
fprintf(FP, "This is a text file!");
fclose(FP);


On the DS you have to call fatInitDefault() before doing any file I/O too.
_________________
I'm a PSP hacker now, but I still <3 DS.

#132759 - phoenix23 - Fri Jun 29, 2007 5:03 am

Well, I've tried exactly the same thing and it just doesn't work.
Everything compiles and runs but the file does not get created anywhere at all.
Is there anything else that needs to be done?

#132761 - Ant6n - Fri Jun 29, 2007 5:07 am

dldi patching?

#132763 - phoenix23 - Fri Jun 29, 2007 5:16 am

Ok, I've found my problem.

I am unable to install the "libfat" library correctly. Everything was running on my emulator but my nintendo DS actually complained when I try to use "fatInitDefault".
Initially, I tried to create a new directory called "libfat" and compile the source code. However, I got a linker error saying that "-lfat" not found.
Thus, I copied the ".a" file and the "fat.h" file into my "libnds" folder structure, and complied again. The project compiles,but does not run.
Also, could anyone provide some links which illustrate how to go about creating a make file?

Thank you for your replies :-)

#132765 - phoenix23 - Fri Jun 29, 2007 5:27 am

Well guys, I had to patch it to get it up and running :-)
Thank you very much for the prompt replies.

#132880 - Wonder Boy - Sat Jun 30, 2007 11:01 pm

phoenix23 wrote:
Well guys, I had to patch it to get it up and running :-)
Thank you very much for the prompt replies.

Hi, I wonder this works in no$gba or another emulator... This is thus?

Greetings.

#142195 - phoenix23 - Fri Oct 05, 2007 11:51 pm

I did try to get it running on Dualis but all I get is a blank screen. However, if I transfer the file to the console, everything is fine.