A question on strings.....
Circuitbuilder9
Posts: 85
Hi, all.
Two questions:
if a variable is an array, and you "bytemove" like this:
byte array[30]
byte copy[90]
bytemove(@array, @copy, 30),
will the entire string of bytes be copied to the entire array of (array), since there are only 30 of the bytes, and only 30 bytes are being copied from a larger string?
Number 2,
In a str(string) instruction, if you copied characters by each byte onto the string, how would you code that?
like this? : (ex) lcd.str(@array)
Would the entire string put on previously (if that's the answer) into the array of (array)?
We'll use the string from the previous question.
Two questions:
if a variable is an array, and you "bytemove" like this:
byte array[30]
byte copy[90]
bytemove(@array, @copy, 30),
will the entire string of bytes be copied to the entire array of (array), since there are only 30 of the bytes, and only 30 bytes are being copied from a larger string?
Number 2,
In a str(string) instruction, if you copied characters by each byte onto the string, how would you code that?
like this? : (ex) lcd.str(@array)
Would the entire string put on previously (if that's the answer) into the array of (array)?
We'll use the string from the previous question.
Comments
2) There isn't really a "str(string)" instruction. There happen to be subroutines provided as part of several I/O objects (packages) that take the starting address of an array of bytes that contains a 'string' of characters terminated by a byte containing zero. This is considered to be a 'string' by convention.
A ".str" method in an I/O object, say for displaying on an LCD, is passed the starting address of a byte array, picks up bytes from the array, one at a time, and, if the byte isn't a zero, passes the byte to a single character display routine for the LCD. If the byte is zero, the routine exits. It looks like this:
One more thing: would this piece of code work?
I am using Serial_Lcd as the lcd.object.
The mbuf is the main piece of larger arrays, and the sbuf is the array where it only holds 32 bytes.
I want to know if the 32 bytes (which will be characters) will be interfaced correctly.
It's better to copy only 31 bytes, so you have always an ending zero (sbuf is initailized with all zeroes on declaration).
Andy
bytemove(b_Ptr2b_RxString, RxStringAddr, strsize(RxStringAddr))
and
bytemove(@b_suffix, RxStringAddr, strsize(RxStringAddr) +1) ' copy from RxStringAddr to @suffix, size + 1 to have the terminating 0
Or in your case
bytemove(@array, @copy, strsize(@copy))
and for bytefill
bytefill(@tmp_addr, 0, strsize(tmp_addr))