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 > Palib and Fat[help]

#127320 - ghaxaq - Tue May 01, 2007 6:04 pm

Hi I am currently developing a game with, and I would like to implement a high score system. I've been able to read and write using fat, but I would like to know how can I read and write from the second line of the text file.

Thanks in advance!

#127338 - tepples - Tue May 01, 2007 7:52 pm

Try loading the entire text file, finding all newlines, replacing the second line in memory, and writing out the text file. I'm writing a text editor right now, so I know some of what you're dealing with.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#127378 - HyperHacker - Wed May 02, 2007 1:12 am

That method will work, but if you want to deal with large files, it'll be slow and will limit the size of the file to the amount of free RAM. Keep that in mind if you plan to do anything involving files over, say, 512K on the DS. A way you might do this without this restriction is to only read/write a certain number of characters at a time instead of the entire file.
_________________
I'm a PSP hacker now, but I still <3 DS.

#127410 - ghaxaq - Wed May 02, 2007 8:05 am

Could you please post a piece of the code I should use? Thanks alot.
_________________
ghaxaq.wordpress.com

#127413 - josath - Wed May 02, 2007 8:52 am

Both C and C++ have built in commands to read a single line of text at once. fgets() in C, and .readline() in c++? i forget now

#127464 - tepples - Wed May 02, 2007 6:42 pm

You can directly overwrite a line in a file as long as it has the same number of bytes as the line you are replacing. Otherwise, you have to read/modify/write the whole file. If the file is bigger than RAM, you will have to read/modify/write to a second file, delete the first file, and rename the second file to the first file's name.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.