|
3 registered members (AndrewAMD, Grant, Neb),
908
guests, and 6
spiders. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: returning string.
[Re: MMike]
#259812
04/07/09 20:26
04/07/09 20:26
|
Joined: Jul 2004
Posts: 1,710
MMike
OP
Serious User
|
OP
Serious User
Joined: Jul 2004
Posts: 1,710
|
its returning blank text :s
edit:forget.. i had to initialize the string dont know why.
for example if i say:
STRING* text1="#200";
and then str_cat(text1,"hello");
it wont work .. i must say first.
str_cpy(text1,""); then the str_cat .. weird..
Can someone confirm this too? coulb be some sort of bug.
Last edited by MMike; 04/07/09 20:34.
|
|
|
Re: returning string.
[Re: MMike]
#259820
04/07/09 21:25
04/07/09 21:25
|
Joined: Feb 2006
Posts: 385 Oldenburg,Germany
Ralph
Senior Member
|
Senior Member
Joined: Feb 2006
Posts: 385
Oldenburg,Germany
|
This is not a bug. If you initialize the string like "str_create("#100")" the str_create funktion fills the hole string with 100 spaces(" "). So the string is full and you need to clear it first if you want to fill it with text. For example try this:
STRING* tmpStr = str_create("#10"); //creates a string that contains 10 spaces
str_trunc(tmpStr,1); //cut the last space and we can fill this position with a character
str_cat(tmpStr,"X"); //lets put an X on the end of the string
//lets print the string
printf("This is what the \"tmpStr\" contains:\n%s",_chr(tmpStr));
Not tested, but should work!
|
|
|
Re: returning string.
[Re: MMike]
#259871
04/08/09 02:34
04/08/09 02:34
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
I used to have trouble with strings. Just remember; STRING* xxxx = "contents"; //is only outside a function STRING* xxxx = str_create("contents"); //is only inside a function Also, no need for the str_cpy when using my function. MyFunction CREATES a string and RETURNS the pointer to it. So when you use MyFunction, it should store its pointer into an UN_ALLOCATED pointer, like in my example-main. If you want to put the results of MyFunction into a string that already exists, do so like this.
...
STRING* temp_string = MyFunction();
str_cpy(Existing_String, temp_string);
str_remove(temp_string);
...
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: returning string.
[Re: EvilSOB]
#259874
04/08/09 03:07
04/08/09 03:07
|
Joined: Jul 2004
Posts: 1,710
MMike
OP
Serious User
|
OP
Serious User
Joined: Jul 2004
Posts: 1,710
|
Thanks.
Last edited by MMike; 04/08/09 03:11.
|
|
|
Re: returning string.
[Re: MMike]
#259907
04/08/09 07:43
04/08/09 07:43
|
Joined: Oct 2007
Posts: 5,209 İstanbul, Turkey
Quad
Senior Expert
|
Senior Expert
Joined: Oct 2007
Posts: 5,209
İstanbul, Turkey
|
str_cpy(Existing_String, MyFunction());
actually this^ should work too.
3333333333
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|