Page 1 of 1
Pointer in a Structure
Posted: Thu Oct 28, 2004 12:36 pm
by Killswitch
What I would like to do is have a pointer in a structure so I can read a file in a pack then later write that data. This is what i've tried:
Code: Select all
Structure a
*a
b.l
endstructure
dim defile.a(10)
defile\a=nextpackfile()
defile\b=packfilesize()
createfile(0,"bob.txt")
writedata(defile\a,defile\b)
closefile(0)
Thats not my code exactly, but it is what I've been trying to do. When I try to write the data to a file PB says that the pointer is null. Is there a way around this, or is it just not posible?
Posted: Thu Oct 28, 2004 12:46 pm
by freedimension
I've been using this
Code: Select all
Structure ByteArray
b.b[0]
EndStructure
Structure Data
*data.ByteArray
EndStructure
*x.Data = AllocateMemory(100)
*x\data\b[0] = 0
Posted: Thu Oct 28, 2004 1:02 pm
by Killswitch
Thank ye very much!
Posted: Thu Oct 28, 2004 1:05 pm
by freedimension
This way you can adress every single Byte directly using the static-Array [x] Syntax. Very usefull.
Posted: Thu Oct 28, 2004 1:45 pm
by GedB
killswhich,
In you original solution you dim defile as an array, then access it as a variable.
defile\a when it should be defile(1)\a.
Posted: Thu Oct 28, 2004 1:47 pm
by Killswitch
Thanks, I have been doing that with my code but the real stuff is upstairs on my internet-free 98 box, you won't believe the amount of problems that mistake has caused me though!
Posted: Thu Oct 28, 2004 2:52 pm
by GedB
~I see one problem with your code: the fact is thats not a array~