Sscanf Help
#1

Hello! I'm trying to get from an array the data using sscanf. I'm doing this:

Код:
// The array contains this: "0,5,5,0,3".
new a[5];
sscanf(PlayerInfo[playerid][Inventory], "p<,>a<i>[5]", a);
for (new s; s < 5; ++s)
{
    if (a[s]) SendClientMessage(playerid, -1, a[s]);
}
But I'm getting only the first "5", the other items are not printed.
Reply
#2

Anyone?
Reply
#3

I don't have my pc now but it should be a<i>[5] only without the p..
Reply
#4

Quote:
Originally Posted by Dayrion
Посмотреть сообщение
I don't have my pc now but it should be a<i>[5] only without the p..
Sscanf retrieves the data between the p<,> (comma). This is a workable example:

Код:
new panels, doors, lights, wheels;
sscanf(Vehicle[id][VisualDamage], "p<|>dddd", panels, doors, lights, wheels);

// VisualDamage is a string that contains 0|3|4|2 and I recive: panels = 0 doors = 3 lights = 4 wheels = 2
What I have is this:

Код:
a[6];

I want to retrieve the data spaced by commas (,) and insert the data in the "a" array:

// PlayerInfo[playerid][Inventory] is a String that contains "0,5,5,0,3,"
sscanf(PlayerInfo[playerid][Inventory], "p<,>a<i>[6]", a);

for (new s; s < 6; ++s)
{
    if (a[s]) SendClientMessage(playerid, -1, a[s]);
}
But I'm only getting as output:

Код:
[13:38:23] HidroDF says: 5
And I need to recive the entire string without the zeros, like:

Код:
[13:38:23] HidroDF says: 5
[13:38:23] HidroDF says: 5
[13:38:23] HidroDF says: 3
Reply
#5

You are doing things wrong.Variable a is integer array you can't pass it as string to sendclientmessage use sscanf's string specifier to initialise the variable a as a string.

Do something like this if you want to use the variable in sendclient message

PHP код:
sscanf("0,5,5,0,3","p<,>ccccc" ,a[0],a[1],a[2],a[3],a[4]); 
Your method has no problem but the problem was that you passed integer array to sendclientmessage.
Reply
#6

This is working fine.
PHP код:
main()
{
    new 
a[] = "2,1,3,4"b[5];
    
printf("-----");
    if(
sscanf(a"p<,>a<i>[5]"b))
        print(
"debug");
    for (new 
s5; ++s)
    {
        
printf("%i & %i"a[s], b[s]);
    }

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)