2 registered members (vicknick, AndrewAMD),
1,292
guests, and 3
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
adding additional numbers to an existing var
#449811
03/31/15 21:41
03/31/15 21:41
|
Joined: Aug 2005
Posts: 199 houston
seneca
OP
Member
|
OP
Member
Joined: Aug 2005
Posts: 199
houston
|
Like the subject line reads, I've been beating my head against the wall on how to program adding an additional number to a variable of numbers that already exist. what I mean is if I have a variable called set_numbers:
var set_numbers = 10;
now I want to add the numbers 23 to the back end of it, so that now set_number is = 1023, but the numbers being added is off the fly and maybe totally random.
I've tried using an array. even tried str_for_num and str_to_num, inkey and some other things to stack the numbers behind each other. I know there must be a way, but I just can't seem to figure it out. any help would be appreciated. Thanks.
a8 commercial
|
|
|
Re: adding additional numbers to an existing var
[Re: seneca]
#449813
03/31/15 21:51
03/31/15 21:51
|
Joined: May 2009
Posts: 5,370 Caucasus
3run
Senior Expert
|
Senior Expert
Joined: May 2009
Posts: 5,370
Caucasus
|
I would suggest to use string for adding the numbers, then convert it to variable. Something like (not tested):
STRING* setNumStr = "10";
void test(){
str_cat(setNumStr, "23");
var number = str_to_num(setNumStr);
}
Maybe it's no the fastest way to do it, but it should work Edit: check str_cat_num too! Best regards!
Last edited by 3run; 03/31/15 22:09. Reason: added str_cat_num
|
|
|
Re: adding additional numbers to an existing var
[Re: EpsiloN]
#449832
04/01/15 10:37
04/01/15 10:37
|
Joined: Aug 2005
Posts: 199 houston
seneca
OP
Member
|
OP
Member
Joined: Aug 2005
Posts: 199
houston
|
Thanks, you guys for the replies. I will test it out.
a8 commercial
|
|
|
Re: adding additional numbers to an existing var
[Re: seneca]
#449840
04/01/15 12:55
04/01/15 12:55
|
Joined: Aug 2005
Posts: 199 houston
seneca
OP
Member
|
OP
Member
Joined: Aug 2005
Posts: 199
houston
|
Worked like a dream. It's amazing that I didn't think of it before. Thanks you guys for your help.
a8 commercial
|
|
|
Re: adding additional numbers to an existing var
[Re: seneca]
#449901
04/02/15 08:36
04/02/15 08:36
|
Joined: Jun 2007
Posts: 1,337 Hiporope and its pain
txesmi
Serious User
|
Serious User
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
|
A solution with no strings:
int int_glue ( int n1, int n2 )
{
int n2b = n2;
for ( ; n2b>0; n2b/=10 )
n1 *= 10;
n1 += n2;
return n1;
}
void main ()
{
int a = 12345;
int b = 67890;
int c = int_glue ( a, b );
error ( str_for_int(NULL, c) );
}
Salud!
|
|
|
Re: adding additional numbers to an existing var
[Re: txesmi]
#449909
04/02/15 10:12
04/02/15 10:12
|
Joined: May 2009
Posts: 5,370 Caucasus
3run
Senior Expert
|
Senior Expert
Joined: May 2009
Posts: 5,370
Caucasus
|
|
|
|
|