Page 1 of 1

Formatted string problem

PostPosted: Mon May 28, 2012 7:12 pm
by SuperSonic
Hey guys! I have a deep question. I wanted to create my own version of the openUrl() function. Mine was supposed to do the same thing except that it would take in a formatted string like sprintf(). Here's the function I made:
Code: Select all
void url(const char *__format, ...)
{
    openUrl(__format);
}
Now of course, this deosn't work. Can anyone tell me how to fix it? A point will be your reward :)

Thanks!
SuperSonic

Re: Formatted string problem

PostPosted: Mon May 28, 2012 7:16 pm
by Hblade
just define it :D Like this maybe
Code: Select all
#define url openUrl


To use:
Code: Select all
url("url here");


it wont turn yeller' though.

Re: Formatted string problem

PostPosted: Mon May 28, 2012 7:19 pm
by SuperSonic
Haha, that's not exactly what I mean. I want it so that I can do this:
Code: Select all
url("www.%s.com", "game-editor");
:D

Re: Formatted string problem

PostPosted: Mon May 28, 2012 7:42 pm
by Hblade
oh xD I get it. Quite simple actually. First create 2 variables, each char variables. named:

wName, fType

Now do this:
Code: Select all
void setWeb(char*webName, char*formatType)
{
    sprintf(wName, webName);
    sprintf(fType, formatType);
}



now you can do your function:
....

OH WAIT.. I see what you mean now!... nvm that is hard xD

Re: Formatted string problem

PostPosted: Mon May 28, 2012 7:52 pm
by SuperSonic
Hblade wrote:OH WAIT.. I see what you mean now!... nvm that is hard xD
:lol:

Yeah, I know. But it would be so useful. Know what I mean? :D

Re: Formatted string problem

PostPosted: Mon May 28, 2012 8:13 pm
by Hblade
yeah it could :D

Re: Formatted string problem

PostPosted: Mon May 28, 2012 8:49 pm
by skydereign
Well, in that case it doesn't seem too necessary. As you would just use the sprintf beforehand. But, if you just wanted to be able to write custom urls with it, you could do something like this.
Code: Select all
void
url (char* first, char* second, char* third)
{
    char buffer[30];
    sprintf(buffer, "%s.%s.%s", first, second, third);
    openUrl(buffer);
}


The thing is in gE we can't use argument lists. The ellipse operator is supported, but you can't use the varg functions.

Re: Formatted string problem

PostPosted: Tue May 29, 2012 3:59 am
by SuperSonic
skydereign wrote:The thing is in gE we can't use argument lists. The ellipse operator is supported, but you can't use the varg functions.
Aww, that's too bad :(

But I know I can do something like this in pure c++. Could you send me a pm how to do it? (if you have time) :P