Hello,
I have a file similar to the following:
1 2 3 4 5 6 7 8 9 10
I wrote the following program to read this file character by character and convert its numbers to Int
type:
function summer()
inn = open("input.txt","r")
c = 0
while !eof(inn)
c = read(inn, Char)
if c != ' '
println(parse(Int, c))
end
end
end
summer()
I have two questions:
1- Is this program correct?
2- I got the following error:
ERROR: LoadError: ArgumentError: invalid digit: '\n'
Stacktrace:
[1] parse(::Type{Int64}, c::Char; base::Int64)
@ Base ./parse.jl:44
[2] parse
@ ./parse.jl:41 [inlined]
[3] summer()
@ Main /Download/file.jl:341
[4] top-level scope
@ /Download/file.jl:345
[5] include(fname::String)
@ Base.MainInclude ./client.jl:489
[6] run(debug_session::VSCodeDebugger.DebugAdapter.DebugSession, error_handler::VSCodeDebugger.var"#3#4"{String})
@ VSCodeDebugger.DebugAdapter ~/.vscode-oss/extensions/julialang.language-julia-1.127.2-universal/scripts/packages/DebugAdapter/src/packagedef.jl:122
[7] startdebugger()
@ VSCodeDebugger ~/.vscode-oss/extensions/julialang.language-julia-1.127.2-universal/scripts/packages/VSCodeDebugger/src/VSCodeDebugger.jl:45
[8] top-level scope
@ ~/.vscode-oss/extensions/julialang.language-julia-1.127.2-universal/scripts/debugger/run_debugger.jl:12
[9] include(mod::Module, _path::String)
@ Base ./Base.jl:495
[10] exec_options(opts::Base.JLOptions)
@ Base ./client.jl:318
[11] _start()
@ Base ./client.jl:552
Why?
Thank you.