Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, ChrstphFr), 875 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 2 1 2
Re: Problem with saving a string array (game_save / game_load) [Re: Superku] #453427
07/26/15 09:58
07/26/15 09:58
Joined: Mar 2014
Posts: 33
Germany: Sachsen
N
Nicros Offline OP
Newbie
Nicros  Offline OP
Newbie
N

Joined: Mar 2014
Posts: 33
Germany: Sachsen
Ok, I'll write a save functions on my own.
I have still one question: I've often written something like this in my source code:
Code:
str_cat(str_create("Test"),str_for_num(NULL,testVar));


But this is wrong, because it allocates memory without a deallocation?
I should use _str() instead of str_create() ?

Last edited by Nicros; 07/26/15 09:59.
Re: Problem with saving a string array (game_save / game_load) [Re: Nicros] #453428
07/26/15 11:04
07/26/15 11:04
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Yes, this is not the correct way to do it.
The unprofessional way to do it (aka my way) is to use some global temporary string:

STRING* str_tmp = "";
..
void dododo(var testnum)
{
str_cpy(str_tmp,"Test");
str_cat(str_tmp,str_for_num(NULL,testnum));
do something with str_tmp, for example "error()" it
}

Alternatively, you could create a string locally and remove it after use:


void dododo(var testnum)
{
STRING* str_tmp;

str_tmp = str_create(""); // of course you can write the "Test" content here, too
str_cpy(str_tmp,"Test");
str_cat(str_tmp,str_for_num(NULL,testnum));
do something with str_tmp, for example "error()" it

ptr_remove(str_tmp);
}


In your case specifically you can use str_printf:
str_printf(NULL,"Test%d",(int)testVar); // see manual -> digits/ format strings


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Page 2 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1