Page 1 of 1

Write string at memory end

Posted: Mon Oct 20, 2008 4:37 pm
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.

Posted: Mon Oct 20, 2008 4:54 pm
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.

Posted: Mon Oct 20, 2008 4:56 pm
by BigB0ss
OMG, it works :D
Thank you very much srod!

Posted: Mon Oct 20, 2008 4:57 pm
by srod
BigB0ss wrote:OMG, it works :D
Thank you very much srod!
You sound surprised that it works! :)