Page 1 of 1

Fixed length strings in structures?

Posted: Fri Oct 10, 2003 6:36 pm
by Kale
When i want to code a fixed length string inside a structure do i have to take into account the null at the end or is this added/ignored for me by PB?

Code: Select all

Structure TEXT
    String.b[11]  ;<----- Does this have to be 11 to make room for the null?
EndStructure
test.TEXT
PokeS(@test\String, "1234567890")  ;<----- string length of 10 characters
Debug PeekS(@test\string)

Posted: Fri Oct 10, 2003 7:37 pm
by ebs
Kale,

The description of PokeS() says "Write a string (including the ending '0') to the specified memory address". That sounds like the byte array does have to be 11 bytes long to allow for the null terminator. This agrees with the usage in C/C++, which arrays in PB structures are supposed to match.

Eric

Posted: Fri Oct 10, 2003 8:14 pm
by Kale
Thanks, wow i've just realised i've never read the manual description of 'PokeS()', i have to slap myself now! :?

Posted: Fri Oct 10, 2003 8:58 pm
by Num3
Kale wrote:Thanks, wow i've just realised i've never read the manual description of 'PokeS()', i have to slap myself now! :?
Lemme help you :mrgreen:

Posted: Fri Oct 10, 2003 9:00 pm
by Proteus
One should read the manual description of all commands! :D

Posted: Sat Oct 11, 2003 9:51 am
by blueznl
i'm trying to convince people that we need fixed length strings in purebasic... (see the thread in 'feature request and wishlist') but haven't been able to convince people yet...

Re: Fixed length strings in structures?

Posted: Wed May 22, 2019 12:59 pm
by alxfrnds
Hello, can anyone tell me what is wrong?
two files: Main and MainSubs
in Main I declare:
Structure AcctRecord
User.s{80}
Password.s{30}
EAddress.s{80}
EPass.s{30}
USign.s{141}
AlwaysSign.i
AlwaysTag.i
Ed.s{64}
Fore.i
Back.i
intMusic.i
QuoteSymbol.s{2}
Thrd.i
Rnb.i
MDir.s{40}
DownDir.s{40}
Font.s{12}
DefMenu.i
DefOpts.i
Tp.s{30}[10]
Script.s{12}[10]
Rotate.i
HNSUrn.s{4}
POP3Url.s{64}
SMTPUrl.s{64}
NNTPUrl.s{64}
ShowAll.s{1}
TimeMonth.l[10]
LogEMail.s{32}
Defaults.i
UBirthday.s{3}
AltDNS.s{4}
RealName.s{80}
SetName.s{20}
MyIP.l
Padd.s{56}
EndStructure
Global.AcctRecord AcctFile
IncludeFile "MainSubs.pb"

In Main Subs:
Procedure ConfigureUser()
strCaseSen.s
strY.s
strRealName.s
strEmail.s
strLOGIN.s
strELog.s
strSetName.s
intTest.i
strLock.s
strUSign.s
strUSign2.s
intTest2.i
strEd.s
strQteSym.s
strTag.s
strDefMenu.s
strEmail.s = ""
strLOGIN.s = ""
strELog.s = ""
strSetName.s = ""
strPassword.s = AcctFile.Password
strEPass.s = AcctFile.Epass
...
When I try to compile, I receive na error: Struct Not Found Password

I'm not sure if I am clear enough.

Thanks any help, this is my first PureBasic Project (using 5.70 LTS)

Alexandre

Re: Fixed length strings in structures?

Posted: Wed May 22, 2019 1:13 pm
by TI-994A
alxfrnds wrote:...error: Struct Not Found Password...
Password has not been defined as a structure. And neither has EPass.

The syntax for accessing structure members:

Code: Select all

strPassword.s = AcctFile\Password
strEPass.s = AcctFile\Epass

Re: Fixed length strings in structures?

Posted: Wed May 22, 2019 1:38 pm
by alxfrnds
TI-994A wrote:
alxfrnds wrote:...error: Struct Not Found Password...
Password has not been defined as a structure. And neither has EPass.

The syntax for accessing structure members:

Code: Select all

strPassword.s = AcctFile\Password
strEPass.s = AcctFile\Epass
Thanks