We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The following works:
@scanf("1.23456", "%f",Float64)
But the following throws an error:
f = "%f" @scanf("1.23456", f,Float64)
ERROR: ArgumentError: mismatch between # of format specifiers and provided args: 0 != 2 Stacktrace: [1] throwa(msg::String) @ Scanf ~/.julia/packages/Scanf/5ncBL/src/Scanf.jl:833 [2] argmismatch(a::Int64, b::Int64) @ Scanf ~/.julia/packages/Scanf/5ncBL/src/Scanf.jl:830 [3] scanner(::BufferedStreams.BufferedInputStream{Base.TTY}, ::Scanf.Format{Base.CodeUnits{UInt8, String}, Tuple{Scanf.LiteralSpec{SubString{String}}}}, ::String, ::Vararg{Any}) @ Scanf ~/.julia/packages/Scanf/5ncBL/src/Scanf.jl:647 [4] scanf(::BufferedStreams.BufferedInputStream{Base.TTY}, ::Scanf.Format{Base.CodeUnits{UInt8, String}, Tuple{Scanf.LiteralSpec{SubString{String}}}}, ::String, ::Vararg{Any}) @ Scanf ~/.julia/packages/Scanf/5ncBL/src/Scanf.jl:126 [5] scanf(::Base.TTY, ::Scanf.Format{Base.CodeUnits{UInt8, String}, Tuple{Scanf.LiteralSpec{SubString{String}}}}, ::String, ::Vararg{Any}) @ Scanf ~/.julia/packages/Scanf/5ncBL/src/Scanf.jl:127 [6] top-level scope @ REPL[89]:1
The context is that I'd like the format to be variable, in some cases f="%f, %f", %f" for instance. Or f="%d, %f", %f, %f, %f" .
f="%f, %f", %f"
f="%d, %f", %f, %f, %f"
How can I programmatically enter the format string?
In addition it would be great to replicate the second part that says Float64 n-times, e.g. if f="%f"^n. Any pointers how to do that? Thanks.
Float64
f="%f"^n
The text was updated successfully, but these errors were encountered:
You are right, @scanf only supports string constants as formats, but you can use one of:
@scanf
julia> f = Scanf.Format("%f") # also variables possible Scanf.format"%f" julia> scanf("12.34", f, 1.5) (1, 12.34) julia> f = Scanf.format"%f" # only constants Scanf.format"%f" julia> scanf("12.34", f, 1.5) (1, 12.34)
Sorry, something went wrong.
For your second question:
julia> n = 5 5 julia> f = Scanf.Format("%f"^n) Scanf.format"%f%f%f%f%f" julia> scanf("1 2 3 4 5 6 7 8", f, zeros(5)...) (5, 1.0, 2.0, 3.0, 4.0, 5.0)
but be aware, that calling Scanf.Format has to interpret the format string each time it is called. So that should not be done inside a hot loop.
Scanf.Format
@KlausC thanks for getting back to me, and for sharing this solution. 🎄
No branches or pull requests
The following works:
But the following throws an error:
The context is that I'd like the format to be variable, in some cases
f="%f, %f", %f"
for instance. Orf="%d, %f", %f, %f, %f"
.How can I programmatically enter the format string?
In addition it would be great to replicate the second part that says
Float64
n-times, e.g. iff="%f"^n
. Any pointers how to do that? Thanks.The text was updated successfully, but these errors were encountered: