Write string at memory end

Just starting out? Need help? Post your questions and find answers here.
BigB0ss
New User
New User
Posts: 9
Joined: Sun Jun 01, 2008 12:28 pm
Location: The Netherlands

Write string at memory end

Post by BigB0ss »

How do I write a string at the end of the memory?
PokeS will write in front of the memory.
I want to read a file into the memory and add this string: tXñ¦Ï¾µ¦ª£ø¡>þ?ÄiA¿Ð to the end of the memory.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Something like :

Code: Select all

fileName$ = "myFile.dat"  ;Make sure this is a valid file.

text$ = "tXñ¦Ï¾µ¦ª£ø¡>þ?ÄiA¿Ð"

lenFile = FileSize(fileName$)
If lenFile > 0
  ;Allocate sufficient memory
    mem = AllocateMemory(lenFile + (Len(text$)+1)*SizeOf(CHARACTER))
  If mem
    If ReadFile(1, fileName$)
      ReadData(1, mem, lenFile)
      CloseFile(1)
      PokeS(mem + lenFile, text$)
    Else
      MessageRequester("Problem!", "Can't open file!")
    EndIf
  Else
    MessageRequester("Problem!", "Insufficient memory!")
  EndIf
Else
  MessageRequester("Problem!", "File is either a folder or is empty!")
EndIf
Depending on the nature of the file you may wish to add some kind of 'terminator' before appending the string etc.
I may look like a mule, but I'm not a complete ass.
BigB0ss
New User
New User
Posts: 9
Joined: Sun Jun 01, 2008 12:28 pm
Location: The Netherlands

Post by BigB0ss »

OMG, it works :D
Thank you very much srod!
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

BigB0ss wrote:OMG, it works :D
Thank you very much srod!
You sound surprised that it works! :)
I may look like a mule, but I'm not a complete ass.
Post Reply