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
printf on var containing a string #388478
12/03/11 17:00
12/03/11 17:00
Joined: Mar 2006
Posts: 1,993
Karlsruhe
PadMalcom Offline OP
Serious User
PadMalcom  Offline OP
Serious User

Joined: Mar 2006
Posts: 1,993
Karlsruhe
Hey guys, I want to output a var containing a string. I tried:

Code:
var jonas = "ASD";	
function main() {
	printf("Test %s", _chr((char*)jonas));
}



But I only receive a "Test (null)". How do I do this right?

Re: printf on var containing a string [Re: PadMalcom] #388482
12/03/11 17:53
12/03/11 17:53
Joined: Sep 2009
Posts: 987
Budapest
Aku_Aku Offline
User
Aku_Aku  Offline
User

Joined: Sep 2009
Posts: 987
Budapest
Code:
STRING* jonas = "ASD";	
function main() {
	printf("Test %s", _chr(jonas));
}



Re: printf on var containing a string [Re: Aku_Aku] #388490
12/03/11 20:02
12/03/11 20:02
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
_chr() is only to convert STRINGs temporarily to CStrings (I assume that it just returns the raw CString pointer of the passed STRING object).


Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Re: printf on var containing a string [Re: WretchedSid] #388549
12/04/11 09:39
12/04/11 09:39
Joined: Mar 2006
Posts: 1,993
Karlsruhe
PadMalcom Offline OP
Serious User
PadMalcom  Offline OP
Serious User

Joined: Mar 2006
Posts: 1,993
Karlsruhe
Okay I was just interested in a solution using a "var" but it seems as if it wasn't possible to ouput string content using printf.

Thanks for the answers guys!

Re: printf on var containing a string [Re: WretchedSid] #388555
12/04/11 10:28
12/04/11 10:28
Joined: Sep 2009
Posts: 987
Budapest
Aku_Aku Offline
User
Aku_Aku  Offline
User

Joined: Sep 2009
Posts: 987
Budapest
Quoted from the official RTFM:
Quote:
Unlike most other functions, this one accepts a variable number of char*, int, or double arguments (no var or float). Make sure in its argument list to typecast a var to (long) or (double), and convert STRING* to char* with the _chr function.


Re: printf on var containing a string [Re: Aku_Aku] #388557
12/04/11 10:46
12/04/11 10:46
Joined: Mar 2006
Posts: 1,993
Karlsruhe
PadMalcom Offline OP
Serious User
PadMalcom  Offline OP
Serious User

Joined: Mar 2006
Posts: 1,993
Karlsruhe
Yepp, that's what I found, too wink

Re: printf on var containing a string [Re: PadMalcom] #388578
12/04/11 17:20
12/04/11 17:20
Joined: Dec 2009
Posts: 128
China
frankjiang Offline
Member
frankjiang  Offline
Member

Joined: Dec 2009
Posts: 128
China
hey ,guy you can used this code .
make your var likes a Pointer is enough.
Code:
var *jonas = "ASD";	
function main() 
{
	printf("Test %s", _chr((char*)jonas));
}




development 3d game is interesting!

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