Maybe being explicit here will help. So,
    
    
    proc scanf*(fmt: cstring): int {.importc, varargs.}
    var a, b, c: cint
    echo scanf("%d %d %d", a.addr, b.addr, c.addr) # 3
    echo a # first 3 cints that
    echo b # user put into stdin
    echo c
    
    
    Run

Save the above in a file called `scan.nim`. Then
    
    
    echo 1 2 3 | nim r scan
    
    
    Run

produces four lines (`"3\n1\n2\n3\n"`) while
    
    
    echo a b c | nim r scan
    
    
    Run

produces four lines of zeros (`"0\n0\n0\n0\n"`) since "a" etc. do not parse as 
decimal integers and since Nim inits them to zero by default (unless you tag 
the names with the `{.noInit.}` pragma or give them some other default).

This said, you should also know that the Nim std lib has `std/strscans` which 
is nicer in many ways except for porting legacy input parsing: 
<https://nim-lang.org/docs/strscans.html>

Reply via email to