COCKOS
CONFEDERATED FORUMS
Cockos : REAPER : NINJAM : Forums
Forum Home : Register : FAQ : Members List : Search :
Old 08-23-2016, 03:11 AM   #1
Nowhk
Human being with feelings
 
Join Date: Mar 2016
Posts: 234
Default Prepend to WDL_String messing chars?

Hi all,

I'm try to easily prepend at the beginning of a WDL_String an additional text.
I've tried this code:

Code:
WDL_String test;
test.Set("Fake Sample.wav");
test.SetFormatted(WAVEPLAYER_PATH_LENGTH, "Error: %s", test.Get());
DBGMSG("test: %s", test.Get());
I'm attemping to get "test: Error: Fake Sample.wav". Instead it outputs "test: Error: Error: mple.wav".

Where am I wrong? I can't just prepend a text in this way? I need a support (temp) variable?

Thanks to everybody!
Nowhk is offline   Reply With Quote
Old 08-23-2016, 08:08 AM   #2
Tale
Human being with feelings
 
Tale's Avatar
 
Join Date: Jul 2008
Location: The Netherlands
Posts: 3,645
Default

Quote:
Originally Posted by Nowhk View Post
Where am I wrong? I can't just prepend a text in this way? I need a support (temp) variable?
Yeah, using a temporary copy of the string should work:

Code:
WDL_String test, tmp;
tmp.Set("Fake Sample.wav");
test.SetFormatted(WAVEPLAYER_PATH_LENGTH, "Error: %s", tmp.Get());
DBGMSG("test: %s", test.Get());
The reason is probably because Get() simply returns a pointer to its internal buffer, but then SetFormatted() updates this same buffer. I guess something similar will happen if you try this:

Code:
char buf[260];
strcpy(buf, "Fake Sample.wav");
sprintf(buf, "Error: %s", buf);
printf("test: %s", buf);
Tale is offline   Reply With Quote
Old 08-24-2016, 11:50 PM   #3
Nowhk
Human being with feelings
 
Join Date: Mar 2016
Posts: 234
Default

Quote:
Originally Posted by Tale View Post
The reason is probably because Get() simply returns a pointer to its internal buffer, but then SetFormatted() updates this same buffer. I guess something similar will happen if you try this:

Code:
char buf[260];
strcpy(buf, "Fake Sample.wav");
sprintf(buf, "Error: %s", buf);
printf("test: %s", buf);
Yeah, the same!

Quote:
Originally Posted by Tale View Post
Yeah, using a temporary copy of the string should work
As I thought Thank you again for your time master!
Nowhk is offline   Reply With Quote
Reply

Thread Tools
Display Modes

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 -7. The time now is 10:53 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.