FB II Compiler

PG PRO

Debugging

Memory

System

Mathematics

Resources

Disk I/O

Windows

Controls

Menus

Mouse

Keyboard

Text

Fonts

Drawing

Sound

Clipboard

Printing

Communication

ASM

Made with FB

TEXT

Use C strings


DIM c.256
p$ = "Pascal String"

BLOCKMOVE @p$+1,@c,LEN(p$)
POKE @c+LEN(p$),0

More smarter way is

DIM p$,overwriteprotection%

POKE @p$+LEN(p$)+1,0

Then pass the @p$+1 as c string pointer.

Osamu Shigematsu


Would you consider this simpler?

DIM length;1,pascal$;1,c;256 'pascal$ begins 1 byte before c

c;255 = [CHndl&] 'get c string from handle
length = 255 'set length to 255 for INSTR
length = INSTR(1,pascal$,CHR$(0)) 'set actual length (includes 0 byte)

'Modify pascal$, remembering that the last characer
'is CHR$(0) and must still be so after modification.
'Now c holds your c string.

BLOCKMOVE @c, [CHndl&], length 'copy c string back to handle

This assumes the handle is large enough to accomodate any changes in the length.

Jay


A function to convert a C-style string to a Pascal/Basic style string would look like this:

LOCAL FN MakePascal$(CStrHndl&)
  DIM temp$
'This function stops after the first 255 characters, because that's the
'most a Pascal type string can hold.
  DIM textPtr&
  textPtr& = [CStrHndl&]
  WHILE PEEK(textPtr&) <> 0 AND LEN(temp$) < 255
    POKE @temp$, LEN(temp$) + 1
    POKE @temp$ + LEN(temp$), PEEK(textPtr&)
  WEND
END FN = temp$

Mars