Fixed length strings in structures?

Just starting out? Need help? Post your questions and find answers here.
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Fixed length strings in structures?

Post 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)
--Kale

Image
ebs
Enthusiast
Enthusiast
Posts: 530
Joined: Fri Apr 25, 2003 11:08 pm

Post 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
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post by Kale »

Thanks, wow i've just realised i've never read the manual description of 'PokeS()', i have to slap myself now! :?
--Kale

Image
Num3
PureBasic Expert
PureBasic Expert
Posts: 2810
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Post 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:
Proteus
Enthusiast
Enthusiast
Posts: 113
Joined: Wed Sep 17, 2003 8:04 pm
Location: The Netherlands

Post by Proteus »

One should read the manual description of all commands! :D
P4 2.4GHz, 256 MB, WinXP Pro, onboard video&audio.
The Programmer's Drinking Song:
"99 little bugs in the code,
99 little bugs.
Fix one bug, recompile
100 little bugs in the code."
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6161
Joined: Sat May 17, 2003 11:31 am
Contact:

Post 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...
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
alxfrnds
User
User
Posts: 10
Joined: Fri Jun 30, 2017 1:13 am

Re: Fixed length strings in structures?

Post 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
User avatar
TI-994A
Addict
Addict
Posts: 2512
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Fixed length strings in structures?

Post 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
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
alxfrnds
User
User
Posts: 10
Joined: Fri Jun 30, 2017 1:13 am

Re: Fixed length strings in structures?

Post 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
Post Reply