|
Post by bigbass on Mar 20, 2020 21:45:08 GMT 1
Hello I saw that Peter solved a problem today with string arrays basic-converter.proboards.com/post/12817/threadand I was wondering if we could do it with 2D array with strings and yes it also works change the declare to a 2D DECLARE item[4][15] = { "one", "two", "three", "four"} TYPE char* PRINT "get item ", item[3] FORMAT "%s%s\n" '--- UNDOCUMENTED STRING EXAMPLE Initialize array DECLARE colour$[4] = {"Blue", "Red", "Orange", "Yellow"} TYPE STRING PRINT "------loop array------" PRINT
i=0 WHILE i <4 PRINT colour$[i] INCR i WEND
|
|
|
Post by bigbass on Jun 24, 2020 19:25:56 GMT 1
here is one more that can cause unexpected problems
just want to post a simple demo that can get confusing in the mix of things
what appears to be the same may be different in the end result when you are looking at the complete string size
I think that the array is the way to go when we have to get the complete string size
Joe
'---------------------- SUB usingPointer() '---------------------- LOCAL str TYPE const char* str = "bacon" PRINT sizeof(str) PRINT str END SUB
'---------------------- SUB usingArray() '---------------------- DECLARE d[] = "bacon" TYPE const char '---the size of the string plus the nul character ending PRINT sizeof(d) PRINT d FORMAT "%s\n" END SUB
CALL usingPointer CALL usingArray
TERMINAL OUTPUT
4 bacon 6 bacon
if we use LEN we are ok in bacon
'---------------------- SUB usingPointer() '---------------------- LOCAL str TYPE const char* str = "bacon" PRINT LEN(str) PRINT str END SUB
'---------------------- SUB usingArray() '---------------------- DECLARE d[] = "bacon" TYPE const char '---the size of the sting plus the nul character ending PRINT LEN(d) PRINT d FORMAT "%s\n" END SUB
CALL usingPointer CALL usingArray
TERMINAL OUTPUT
5 bacon
5 bacon
|
|