News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

sscanf for 64-bit integers?

Started by bozo, September 04, 2008, 12:08:48 AM

Previous topic - Next topic

bozo

Hey all

I was trying to use sscanf() function to read a 64-bit decimal value from an input box, %llu and %I64d only seemed to return 32-bit value..


qwNumber dq ?
szNumber db "12345678901234"

invoke sscanf,addr szNumber, "%I64d", addr qwNumber


In the end i wrote a simple conversion using mul/add which does work.. but i was wondering if anyone here knew of a function accessable from assembly to do the job without manually written code?

MichaelW

It works for me:

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    include \masm32\include\masm32rt.inc
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    .data
      qwNumber dq 0
    .code
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start:
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    invoke crt_sscanf, chr$("9223372036854775807"),
                       chr$("%I64d"), ADDR qwNumber
    invoke crt_printf, chr$("%I64d%c"), qwNumber, 10
    invoke crt_printf, chr$("%I64x%c"), qwNumber, 10
    invoke crt_sscanf, chr$("-9223372036854775808"),
                       chr$("%I64d"), ADDR qwNumber
    invoke crt_printf, chr$("%I64d%c"), qwNumber, 10
    invoke crt_printf, chr$("%I64x%c"), qwNumber, 10
    invoke crt_sscanf, chr$("18446744073709551615"),
                       chr$("%I64u"), ADDR qwNumber
    invoke crt_printf, chr$("%I64u%c"), qwNumber, 10
    invoke crt_printf, chr$("%I64x%c"), qwNumber, 10

    inkey "Press any key to exit..."
    exit
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start


9223372036854775807
7fffffffffffffff
-9223372036854775808
8000000000000000
18446744073709551615
ffffffffffffffff
eschew obfuscation

bozo

hmm, i'll need to look at it later, i am using CRTDLL.DLL but haven't tried MSVCRT.DLL (if there is difference, don't know)

GregL

Quote... i am using CRTDLL.DLL but haven't tried MSVCRT.DLL (if there is difference, don't know)

CRTDLL.DLL is the older (now defunct) C run-time library, it came with Visual C++ 4.0, Windows 95 and Windows NT. MSVCRT.DLL is the newer C run-time library. It comes with all versions of Windows since Windows 95B. It also came with Visual C++ 6.0. It's a "well known" DLL. I just read the other day that Microsoft is still updating and improving it, the last update was for Windows Vista.



bozo

Yes, that was the problem alright.
Thanks guys, all working now.