03-08-2005, 09:46 AM
Do we have such FB command to copy a BASIC string into an ASCIIZ array?
If not, how abouit scopy() and inversely, acopy() commands?
Geo
If not, how abouit scopy() and inversely, acopy() commands?
Geo
BASIC strings copied to/from ASCIIZ arrays
|
03-08-2005, 09:46 AM
Do we have such FB command to copy a BASIC string into an ASCIIZ array?
If not, how abouit scopy() and inversely, acopy() commands? Geo
03-08-2005, 09:50 AM
we sort of do... it's called "byte ptr". there's an example that comes with fb, under the examples dir called "bytestring.bas". basically, to convert from string->byte ptr, use
Code: dim bptr as byte ptr,st as string Code: dim bptr as byte ptr,st as string
ttp://m0n573r.afraid.org/
Quote:quote: "<+whtiger> you... you don't know which way the earth spins?" ... see... stupidity leads to reverence, reverence to shakiness, shakiness to... the dark side...phear
03-08-2005, 11:05 AM
...and best of all that doesn't copy any string data. FreeBASIC strings are already asciiz.
03-09-2005, 05:52 AM
Really? Let me see. Borrowed some code from bytestring.bas and added some more.
Code: dim p as byte ptr Code: dim p as byte ptr Goodie! Goodie! :bounce: Geo
03-15-2005, 02:19 AM
While this topic is open and about strings:
If I use GET to read in a file, and want to stash it in a structure: Is this structure: Code: type foo functionally equivalent to this structure: Code: type foo2 Let's say my data consisted of "Hello!" and the number 42. If I GET this data into these structures, which one will be more correct? I'm used to the C way of doing it. Does FB silently account for the null zero by putting it where byte 6 should be (byte 5 being the last human readable character)? In another way of asking, will the string look like this if I use foo2: 'H' 'e' 'l' 'l' 'o' '!' '\0' or 'H' 'e' 'l' 'l' 'o' '\0' or 'H' 'e' 'l' 'l' 'o' '!' (The null zero is just thrown away, this is equivalent to what would happen with type foo.) Also, do size functions return the actual size of the string, the size of the characters in the string, the number of characters including/excluding the null zero, or what?
03-15-2005, 03:05 AM
In VBDOS they would equivalent, but unfortunately in FreeBASIC a STRING * 6 is actually 7 bytes to make room for a 6 byte string plus a null. This makes STRING * n data types much easier to use for strings than in QB, but renders then totally useless for non-string data.
03-15-2005, 03:14 AM
So what happens if I GET data into this string? Does it only read 6 bytes, leaving the read cursor pointing at the next byte?
03-15-2005, 03:18 AM
Nope. If you GET a STRING * 6, it will actually read 7 bytes.
In FB, STRING * n data types are virtually useless for anything except null terminated strings, which is a shame - they were so much more versatile in QB, where a STRING * n was n bytes. So if you know that the next 10 bytes in the file are reserved for a null terminated string, then you read in a STRING * 9.
03-15-2005, 03:29 AM
Ok, I think that answers the bulk of those questions.
I essentially want to read in a set number of bytes, like a file header string with no null terminator, and compare it like a string. Apparently that has to be done like in C with a byte array. That is kind of too bad. What exactly is the string descriptor for, then? The biggest reason for having strings be null terminated is so you only need a pointer set to the first byte, then functions read till they hit a zero.
03-15-2005, 11:09 AM
Descriptors are just structures for strings. Strings in FB are technically "C" char type strings. which is why it's able to use C DLLS w/o any glitch. Descriptors are structures that v1c made to make strings easier to manage in FB(like QB).
Ie. It prolly stores, the pointer, length, etc. If you plan to GET a byte then use a the BYTE data type in FB. ;*) |
« Next Oldest | Next Newest »
|