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 > Accessing text files

#78617 - rmco2003 - Sat Apr 08, 2006 2:28 pm

I'm currently working on a small questions and answers type application, I've got 35 questions and I can have up to 5 answers per question, I've currently thought of making a structured array to store everything for use like this

Code:
   typedef struct
   {
      int quantityans; //Amount of answers required for the question
      char question[100],answer1[60],answer2[60],answer3[60],answer4[60],answer5[60];
   } qanda;
   qanda quiz[35];


but I'd rather have everything stored in a seperate file that I can access one question at a time. I'm using PAlib for coding at the moment, what's the best way for me to go about this?

#78644 - knight0fdragon - Sat Apr 08, 2006 5:35 pm

if i were u create 2 files, 1 for questions and one for answers

then for the index of the question, u just multiply the index of the answer by 5

i = 5
so quesion[i]
answerr[i*5]
_________________
http://www.myspace.com/knight0fdragonds

MK DS FC: Dragon 330772 075464
AC WW FC: Anthony SamsClub 1933-3433-9458
MPFH: Dragon 0215 4231 1206

#78673 - rmco2003 - Sat Apr 08, 2006 9:00 pm

I still need the code to actually access the text files, I don't know how to do that, and the PAlib wiki doesn't cover it

#78680 - knight0fdragon - Sat Apr 08, 2006 9:20 pm

i dont use PA lib, so perhaps u can just use a C file, unless of course u want this to be external or something
_________________
http://www.myspace.com/knight0fdragonds

MK DS FC: Dragon 330772 075464
AC WW FC: Anthony SamsClub 1933-3433-9458
MPFH: Dragon 0215 4231 1206

#78681 - tepples - Sat Apr 08, 2006 9:22 pm

Are you using a GBA flash card, a GBAMP, a SuperCard CF, an M3 CF, a SuperCard SD, an M3SD, or FlashMe+WMB?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#78682 - swimgod - Sat Apr 08, 2006 9:27 pm

Quote:
I tested it on my GBAMP and it works,

he said that in another post,
so i guess he uses gbamp for testing :P
and development tepples
_________________

1x WII 2x remotes
2x NDS/L(FMv7-ORG:v4,FMv7-org:DSL)
1x GBAMP
2x 1gb (MicroDrive{typeII}&SanDisk{typeI})
1x SuperPass2
1x Supercard-CF

MoonShell skins


Last edited by swimgod on Sat Apr 08, 2006 10:07 pm; edited 1 time in total

#78684 - rmco2003 - Sat Apr 08, 2006 9:57 pm

well I'm planning on using a flash cart since I want to have save slots stored in SRAM, I'm using both a flash cart and a GBAMP for testing at the moment since I'm not using GBFS at the moment

#78687 - tepples - Sat Apr 08, 2006 10:30 pm

For traditional (NOR based) GBA flash carts, as well as M3 SD and SC SD, the easiest way is GBFS. For GBAMP and other CF adapters, the easiest way is Chishm's FAT driver. For FlashMe+WMB, you'll need to use GBFS+bin2s.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#78730 - rmco2003 - Sun Apr 09, 2006 7:53 am

Well I'll be using GBFS but I just need to know how to store a line of text into a variable from a text file...

#78783 - tepples - Sun Apr 09, 2006 7:50 pm

To copy a file into a piece of source code containing a declaration of the contents of that file into a variable, use
Code:
bin2s file.txt > file.c

Compiling this C file into your app will give you symbols file_txt[] and file_txt_size.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#79227 - rmco2003 - Wed Apr 12, 2006 9:25 am

So is that bin2s function a command line function or do I actually use that within my code? If I use the function that means it will convert the whole file into string format correct? How would I be able to read data from it line by line? The format for my text file would be as follows:

Question Text
Required amount of answers (a number)
Answer 1 Text
..(and so on up to the amount of answers required)
Amount of answers required(a number - 1 or 2)
Answer slot 1(used to verify which answers are correct)
Answer slot 2(if required)

so an example would be

How many answers are correct?
4
One answer
Two answers
Three answers
Four answers
1
1

So if you picked 'One answer' it would be correct, all of the other answers would be incorrect. I've got this code partially working, just some minor problems with sprite generation for the buttons.

#79237 - tepples - Wed Apr 12, 2006 12:44 pm

rmco2003 wrote:
So is that bin2s function a command line function

Yes. It's included with the official GBFS distribution, and it should be included with recent devkitARM.

Quote:
If I use the function that means it will convert the whole file into string format correct? How would I be able to read data from it line by line?

There would be a \n after each line.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#79260 - chishm - Wed Apr 12, 2006 2:00 pm

tepples wrote:
rmco2003 wrote:
If I use the function that means it will convert the whole file into string format correct? How would I be able to read data from it line by line?

There would be a \n after each line.

Also be sure to consume any \r characters in windows text files.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com