|
Re: Getting 2 ints in one STRING
[Re: Razoron]
#342202
09/24/10 16:50
09/24/10 16:50
|
Joined: Apr 2010
Posts: 172
wdlmaster
Member
|
Member
Joined: Apr 2010
Posts: 172
|
str_cpy (s,"");
str_cat (s,format,int1);
str_cat (s,format,int2);
BUT: you can't really reduce bandwidth this way! Only with very small numbers. Example: A 32bit integer is 4 byte, no matter how big the number is (up to it's maximum) - but if you represent high values as string and not as binary, it needs way more bytes. For example the value 2147483647 needs already 10 byte (instead of 4)! With 10 bytes (binary), you could store two long and one short integer(s), or 5 short integers etc...
|
|
|
Re: Getting 2 ints in one STRING
[Re: wdlmaster]
#342207
09/24/10 18:12
09/24/10 18:12
|
Joined: May 2009
Posts: 445 Peine, Germany
Razoron
OP
Senior Member
|
OP
Senior Member
Joined: May 2009
Posts: 445
Peine, Germany
|
Yes, but I don't want to send them in a row. @ your code: And how to extract them?
function send(int i1, int i2)
{
STRING* s;
str_cpy(s, "");
str_cat(s, i1);
str_cat(s, i2);
send(s);
}
function recieve(STRING* s)
{
int i1;
int i2;
i1 = ??;
i2 = ??;
}
|
|
|
Re: Getting 2 ints in one STRING
[Re: Razoron]
#342208
09/24/10 18:14
09/24/10 18:14
|
Joined: Apr 2007
Posts: 3,751 Canada
WretchedSid
Expert
|
Expert
Joined: Apr 2007
Posts: 3,751
Canada
|
1) Add a seperating character like ! 2) Split the string into the two substrings seperated by the character. 3) Convert both into an integer. 4) ??? 5) Profit
Shitlord by trade and passion. Graphics programmer at Laminar Research. I write blog posts at feresignum.com
|
|
|
Re: Getting 2 ints in one STRING
[Re: wdlmaster]
#342248
09/25/10 16:10
09/25/10 16:10
|
Joined: Jul 2008
Posts: 1,178 England
MrGuest
Serious User
|
Serious User
Joined: Jul 2008
Posts: 1,178
England
|
You must use a seperator for the two numbers. Then, use str_stri to get the position of the seperator and a combination of str_clip and str_trunc to "extract" the two values... You don't always need a seperator if you know the length of the integer you're sending If you're always sending the same length integer, just use str_clip() and str_trunc() to and extract the length you need If you're changing the length of the integer, just concatenate that into the string
|
|
|
|