Strings and things (again!)
Hugh
Posts: 362
Hi,
I'm struggling with strings and things (again!)
I have a array of bytes, 'dataGS', that contains [67, 71, 77, 65, 66, 72, 73, 66] and that I would like to show on an LCD as a string. Another byte array, 'scratchPad', is used to shuffle things about.
What I thought I was doing was moving the first four characters of 'dataGS' into 'scratchpad' and then treat this as a string.
I've tried using lcd.str(@scratchpad).
Am I being naive that this will create a string (with a trailing zero, etc.,)?
Thanks
Hugh
I'm struggling with strings and things (again!)
I have a array of bytes, 'dataGS', that contains [67, 71, 77, 65, 66, 72, 73, 66] and that I would like to show on an LCD as a string. Another byte array, 'scratchPad', is used to shuffle things about.
What I thought I was doing was moving the first four characters of 'dataGS' into 'scratchpad' and then treat this as a string.
CON
dataGS[20] = [67, 71, 77, 65, 66, 72, 73, 66]
VAR
scratchpad[20]
...
PUB Main
bytefill(@scratchpad, 0, 20) 'Fill scratchpad with zeroes
bytemove(@scratchpad, @dataGS, 4)
lcd.str(scratchpad)
I've tried using lcd.str(@scratchpad).
Am I being naive that this will create a string (with a trailing zero, etc.,)?
Thanks
Hugh
Comments
Maybe you should move the arrays out of the CON section and into a DAT section. I'm looking through the manual (v1.2) and I don't see anything about arrays in the CON section. Instead, I'd try something like:
Sorry - my copy-and-paste error.
For initialized byte arrays you can use a DAT section, zero filled arrays are defined in a VAR section. In both cases you need the byte keyword:
Andy
Thank you!