Gamestudio Links
Zorro Links
Newest Posts
loading historical data 1st time
by AndrewAMD. 04/14/23 12:54
Trade at bar open
by juanex. 04/13/23 19:43
Bug in Highpass2 filter
by rki. 04/13/23 09:54
Adding Limit Orders For IB
by scatters. 04/11/23 16:16
FisherN
by rki. 04/11/23 08:38
AUM Magazine
Latest Screens
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Hecknex World
Who's Online Now
3 registered members (AndrewAMD, Grant, Neb), 908 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
rki, FranzIII, indonesiae, The_Judge, storrealba
18919 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
returning string. #259768
04/07/09 15:57
04/07/09 15:57
Joined: Jul 2004
Posts: 1,710
MMike Offline OP
Serious User
MMike  Offline OP
Serious User

Joined: Jul 2004
Posts: 1,710
hello how can i do this:

function hello(){

return("hello");
}


or string hello(){return("hello");}

and call str_cpy(mytext,hello());

Re: returning string. [Re: MMike] #259769
04/07/09 16:03
04/07/09 16:03
Joined: Jul 2004
Posts: 1,710
MMike Offline OP
Serious User
MMike  Offline OP
Serious User

Joined: Jul 2004
Posts: 1,710
im trying this as parameter to return a pointer...

STRING* rss_h_title="#200";

function rss_read_title(){
str_cpy(rss_h_title,"HELOO");
return(&rss_h_title);
}

then error(rss_read_title());


the engine says there is no error with this.. but the text is not the hello but "9+n Erx Fje ...";

Re: returning string. [Re: MMike] #259774
04/07/09 16:22
04/07/09 16:22
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Code:
STRING*  MyFunction()
{
   STRING* tmp_string = str_create("hello");
   return(tmp_string);
}

OR

STRING*  MyFunction()
{
   return(str_create("hello"));
}

and call it with

function main()
{
   ...
   STRING* Returned_string;
   ...
   Returned_string = MyFunction();
   ...
   //remember you will need to use
   str_remove(Returned_string);
   //when youve finished with it.
}



"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: returning string. [Re: EvilSOB] #259792
04/07/09 18:06
04/07/09 18:06
Joined: Jul 2004
Posts: 1,710
MMike Offline OP
Serious User
MMike  Offline OP
Serious User

Joined: Jul 2004
Posts: 1,710
thanks..

can i use:

function main()
{
...
STRING* Returned_string;
...
str_cpy(Returned_string,MyFunction);
...
//remember you will need to use
str_remove(Returned_string);
//when youve finished with it.
}

Re: returning string. [Re: MMike] #259812
04/07/09 20:26
04/07/09 20:26
Joined: Jul 2004
Posts: 1,710
MMike Offline OP
Serious User
MMike  Offline 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 Offline
Senior Member
Ralph  Offline
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:
Code:
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: Ralph] #259863
04/08/09 01:11
04/08/09 01:11
Joined: Jul 2004
Posts: 1,710
MMike Offline OP
Serious User
MMike  Offline OP
Serious User

Joined: Jul 2004
Posts: 1,710
You really right, i havent tested, but i can see it works. I forgot that concept the #100 fill the whole string...

Re: returning string. [Re: MMike] #259871
04/08/09 02:34
04/08/09 02:34
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
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.
Code:
...
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 Offline OP
Serious User
MMike  Offline 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 Offline
Senior Expert
Quad  Offline
Senior Expert

Joined: Oct 2007
Posts: 5,209
İstanbul, Turkey
str_cpy(Existing_String, MyFunction());

actually this^ should work too.


3333333333
Page 1 of 2 1 2

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