Confusion: PAWN doesn't differentiate between i and d specifiers?
#1

Having used C languages before, I already realize that there's a difference between - the two specifiers - i and d when it comes to output and input. I had never bothered to test it out in PAWN though, but by chance it popped in my head lately and this is when the weird results came up...

Test code:
pawn Code:
// output test...
printf("printf(output) '051' with d specifier: %d", 051);
printf("printf(output) '051' with i specifier: %i", 051);
// input test...
new integer;
// first
sscanf("051", "d", integer);
if(integer == 51) // still octal
    print("sscanf(input) '051' with d specifier: 51");
else if(integer == 41) // 41 the decimal of 051
    print("sscanf(input) '051' with d specifier: 41");
// second
sscanf("051", "i", integer);
if(integer == 51) // still octal
    print("sscanf(input) '051' with i specifier: 51");
else if(integer == 41) // 41 the decimal of 051
    print("sscanf(input) '051' with i specifier: 41");
Result:
Code:
printf(output) '051' with d specifier: 51
printf(output) '051' with i specifier: 51
sscanf(input) '051' with d specifier: 51
sscanf(input) '051' with i specifier: 51
Is it my test code? Am I doing it wrong? If so, then can you drop good code that would give out correct/expected results?
Reply
#2

Your code is not wrong. In PAWN generally (this is not a PAWN feature though, "sscanf" is a 3rd-party plugin/function and "format" was made by Kalcor), 'd' and 'i' are treated as the same (optionally signed decimal integer).
AFAIK "format" (and thus "printf") doesn't support octal values at all (though it supports hexdecimal values through the 'x' and 'h' specifier).
"sscanf" on the other hand supports octal values through the 'o' specifier.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)