English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. Blitz Basic

 
 
Thread Tools
Old 20 August 2018, 18:35   #1
peceha
Registered User
 
peceha's Avatar
 
Join Date: Dec 2017
Location: Poland
Age: 48
Posts: 284
How to assign some buffer for a string?

I need to use AddPart_() command and (if I understood it correctly) the modified/final path will be stored in first variable passed to that function (ie. Dirname).
The problem starts here because that variable (buffer in memory) must be long enough to accommodate new path string.
How to do this in blitz?

Thanks
peceha is offline  
Old 20 August 2018, 21:35   #2
Daedalus
Registered User
 
Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 6,381
The Maxlen keyword is used for reserving string space:

Code:
Maxlen myName$ 512
You can then use & to pass the address of the reserved string to any OS calls that need to write to it:

Code:
succ.l = Addpart_(&myName$, &myPart$, 512)
This should write the result back to myName$. I *think* however, that Blitz's temporary string buffer will miss the update, meaning that using myName$ directly afterwards won't reflect the result. Instead, you would need to read the string directly:

Code:
NPrint Peek.s(&myName$)
Or, you could make the change permanent in the variable by reassigning it:

Code:
myName$ = Peek.s(&myName$)

Last edited by Daedalus; 21 August 2018 at 11:19.
Daedalus is offline  
Old 21 August 2018, 01:42   #3
peceha
Registered User
 
peceha's Avatar
 
Join Date: Dec 2017
Location: Poland
Age: 48
Posts: 284
It works!!
And you were right about reading the string directly.
Thanks!!

Just small correction :
Code:
succ.l = Addpart_(myName$, myPart$, 512)
Needs & in front of each variable.
peceha is offline  
Old 21 August 2018, 11:19   #4
Daedalus
Registered User
 
Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 6,381
Quote:
Originally Posted by peceha View Post
It works!!
And you were right about reading the string directly.
Thanks!!

Just small correction :
Code:
succ.l = Addpart_(myName$, myPart$, 512)
Needs & in front of each variable.
Oops, yes, of course... I even said it in the text, just forgot to put them in the example. Fixed now, thanks

As an aside, it is possible to use string parameters without the & for system calls where the string is not modified by the function, just not where the string is to be modified by the system. But it's probably best to use the & just in case.
Daedalus is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
os 3.1 string length limit Miggy support.Apps 1 07 September 2014 21:05
string starts with AGS Coders. Asm / Hardware 24 24 August 2014 16:09
highlight string kkhard Coders. C/C++ 0 15 August 2014 04:26
SetPatch 44+ copyright string amiga_user support.Apps 20 03 April 2011 01:55

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 00:14.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.07319 seconds with 13 queries