Moving strings into an array
Ok so there is a concept I’m trying to work out here, I’m not sure how to go about this but I want to use the fsrw object to get a listing of all of the files on an SD card. I can get the file names by using the fStore.nextfile function, but I am having trouble storing the value into an array. What I have so far:
When I run the code, I get no output. If I change “LONG[noparse][[/noparse] fileList ][noparse][[/noparse] i ] := @tbuf” to “fileList][noparse][[/noparse] i ] := @tbuf” it will work but tbuf is rewritten every time. I made the array a set of longs although this is maybe no the right way to store a string. Tbuf is a pointer to the location that contains the file name, and I need to store that into an array and not the pointer value to the string. Is there a somewhat short way around this? Or do I need to modify the fsrw to buffer the file names and return an address to the buffer? I would much prefer to have fsrw remain unmodified and be able to take the string from the memory location it returns and store it into an array. Also, I do not know how many items may be in the array, basically, there are X amount of files. Any help would be appreciated. This is a simple core concept and I’m sure I could use the concept of storing strings into an array in a few applications. Any help would be appreciated.
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
tvPin = 24
cardPin = 20
obj
term: "tv_text"
fStore: "fsrw"
var
byte tbuf
long fileList[noparse][[/noparse]20]
pub start | r, sta, bytes, i
term.start(tvPin)
' grab the file list up to 20 items for now
GetFileList
i:=0
repeat while not fileList[i] == 0
term.str(fileList[i])
term.out($0D)
i++
pub GetFileList|i
fStore.mount(cardPin)
fStore.opendir
i:=0
repeat while 0 == fStore.nextfile(@tbuf)
LONG[noparse][[/noparse] fileList ][noparse][[/noparse] i ] := @tbuf
i++
[/i][/i]
When I run the code, I get no output. If I change “LONG[noparse][[/noparse] fileList ][noparse][[/noparse] i ] := @tbuf” to “fileList][noparse][[/noparse] i ] := @tbuf” it will work but tbuf is rewritten every time. I made the array a set of longs although this is maybe no the right way to store a string. Tbuf is a pointer to the location that contains the file name, and I need to store that into an array and not the pointer value to the string. Is there a somewhat short way around this? Or do I need to modify the fsrw to buffer the file names and return an address to the buffer? I would much prefer to have fsrw remain unmodified and be able to take the string from the memory location it returns and store it into an array. Also, I do not know how many items may be in the array, basically, there are X amount of files. Any help would be appreciated. This is a simple core concept and I’m sure I could use the concept of storing strings into an array in a few applications. Any help would be appreciated.

Comments
.mp3
1.mp3
the files i have are:
newfile.txt
1.mp3
here is the updated code:
CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 tvPin = 24 cardPin = 20 obj term: "tv_text" fStore: "fsrw" var byte tbuf byte fileList[noparse][[/noparse]20*13] long numFiles pub start | r, sta, bytes, i term.start(tvPin) ' grab the file list up to 20 items for now GetFileList i:=0 repeat while i < numFiles print(@fileList[noparse][[/noparse]13*i]) i++ pub GetFileList|i fStore.mount(cardPin) fStore.opendir i:=0 print(string("entering loop")) repeat while 0 == fStore.nextfile(@tbuf) bytemove(@fileList[noparse][[/noparse]13*i],@tbuf,13) i++ numfiles:=i pub Print(text) term.str(text) term.out($0D)I don't know why this is so difficult, it seems like such a simple concept. any help would be appreciated.
now if I do this:
pub GetFileList|i fStore.mount(cardPin) fStore.opendir i:=0 print(string("entering loop")) repeat while 0 == fStore.nextfile(@tbuf) bytemove(@fileList[noparse][[/noparse]13*i],@tbuf,13) print(@fileList[noparse][[/noparse]13*i]) i++ numfiles:=ithen i will get my full file listing printed out. So for some reason the buffer changes and i am still not receiving the values from the array, but the pointer to a changing tbuf.
Post Edited (ThePenguinMaster) : 7/2/2009 11:43:35 PM GMT
CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 tvPin = 24 cardPin = 20 obj term: "tv_text" fStore: "fsrw" var byte tbuf byte fileList[noparse][[/noparse]20*13] long numFiles pub start | r, sta, bytes, i term.start(tvPin) GetFileList i:=0 repeat while i < numFiles print(@fileList[noparse][[/noparse]13*i]) i++ pub GetFileList|i fStore.mount(cardPin) fStore.opendir i:=0 repeat while 0 == fStore.nextfile(@fileList[noparse][[/noparse]13*i++]) numfiles:=i pub Print(text) term.str(text) term.out($0D)