06.08.2012, 09:46
Hey lads,
I gotta little problem in here.
I was wondering, how can I separate from string integers and assign them into variables.
For example, I've this table:
And a string:
All I wanna do is too loop through this string and get letters into table "_Numbers".
So it would like something like this:
I've already wroten a script to get these numbers:
Okay, I've created 2 global variables (lets say 'at the top of the script)
In main() Ive wroten:
Okay, awesome, when I start my server,
It prints:
6
35
64
1
5
And so on.. So it works.
But:
Is not doing it thing.. in this stock array == iVar and [arrays] are numbers from 0 to X (X = (in number) last repeat of loop).
When I use in main() for e.g. printf(iVar[3]); which should print 1 it prints nothing (same effect you can get with print("\n");
Anyone has any suggestions on how to solve this?
Thx.
Greetz,
LetsOWN
I gotta little problem in here.
I was wondering, how can I separate from string integers and assign them into variables.
For example, I've this table:
pawn Код:
new _Numbers[5];
pawn Код:
//Numbers[128]:
"1.54.63.2.64.96"
So it would like something like this:
pawn Код:
_Numbers[0] = 1;
_Numbers[1] = 54;
//and so on
pawn Код:
stock GetNumbersFromString(string[], array[])
{
printf("'Get Numbers From String' being called");
new _rcst[12];
new arrays = 0;
for(new i = 0; i < strlen(string)*2; i++)
{
if(string[i] != '.')
format(_rcst, 12, "%s%c", _rcst, string[i]);
else if(string[i] == '.')
{
array[arrays] = strval(_rcst);
printf(_rcst);
format(_rcst, 12, "\0");
}
if(string[i+1] == EOS)
break;
}
}
pawn Код:
new intStr[64];
new iVar[4];
pawn Код:
format(intSTr, 40, "6.35.64.1.5.6.4.3.123.4.70.");
GetNumbersFromString(intStr, iVar);
printf(iVar2]);
pawn Код:
// remamber this:
printf(_rcst);
6
35
64
1
5
And so on.. So it works.
But:
pawn Код:
array[arrays] = strval(_rcst);
When I use in main() for e.g. printf(iVar[3]); which should print 1 it prints nothing (same effect you can get with print("\n");
Anyone has any suggestions on how to solve this?
Thx.
Greetz,
LetsOWN