Optional enumerators - sscanf
#1

Hello. I have a problem with a code.

if I put it this code:
pawn Код:
sscanf("1 2 3 4", "E<ii-i-i>(20,30)", quiet_enum);


    printf("%i value 1", quiet_enum[value_1]);
    printf("%i value 2", quiet_enum[value_2]);
    printf("%i value 3", quiet_enum[value_3]);
    printf("%i value 4", quiet_enum[value_4]);
That makes what I want, which is to print 20 and 30 in the value 1 and 2.
but I get an error: sscanf error: Insufficient default values.

I can fix that mistake, by:
pawn Код:
sscanf("1 2 3 4", "E<ii-i-i>(20,30,40,50)", quiet_enum);


    printf("%i value 1", quiet_enum[value_1]);
    printf("%i value 2", quiet_enum[value_2]);
    printf("%i value 3", quiet_enum[value_3]);
    printf("%i value 4", quiet_enum[value_4]);
But I would 1 2 0 0, and not what I want.

How I can fix it ?.
Reply
#2

anyone?
Reply
#3

You should have 3 values there:
Код:
"E<ii-i-i>(20,30,40)"
Because you are updating the first 2 and the last parts of the enum, and remain the 3rd untouched. So sscanf require 3 default values.

You can read this page if you haven't or re-read: https://sampforum.blast.hk/showthread.php?tid=570927
Reply
#4

Quote:
Originally Posted by Gammix
Посмотреть сообщение
You should have 3 values there:
Код:
"E<ii-i-i>(20,30,40)"
Because you are updating the first 2 and the last parts of the enum, and remain the 3rd untouched. So sscanf require 3 default values.

You can read this page if you haven't or re-read: https://sampforum.blast.hk/showthread.php?tid=570927
I did, but still prints, "1-2-0-0".

pawn Код:
enum tranquilos
{
    valor_1,
    valor_2,
    valor_3,
    valor_4
};
new quiet_enum[tranquilos];

// The problem is that the default values are not read.
sscanf("1 2 3 4", "E<ii-i-i>(20, 30, 40)", quiet_enum);
    printf("%i value 1", quiet_enum[valor_1]);
    printf("%i value 2", quiet_enum[valor_2]);
    printf("%i value 3", quiet_enum[valor_3]);
    printf("%i value 4", quiet_enum[valor_4]);
You can try if you want.
Reply
#5

Apparently it's a failure of sscanf. So the solution is:

pawn Код:
sscanf("", "E<ii-i-i>(20, 30, 40)", quiet_enum);
Place empty data. (const data []). There could be "0 0 0 0", and that 0 is also a value.
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)