Skip to content
New issue

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

fmt: Scanln returns "unexpected newline" error on an empty line #9666

Closed
vcaputo opened this issue Jan 22, 2015 · 1 comment
Closed

fmt: Scanln returns "unexpected newline" error on an empty line #9666

vcaputo opened this issue Jan 22, 2015 · 1 comment

Comments

@vcaputo
Copy link

vcaputo commented Jan 22, 2015

I expect an empty string not an error, is this intentional?

@mikioh mikioh changed the title fmt.Scanln returns "unexpected newline" error on an empty line fmt: Scanln returns "unexpected newline" error on an empty line Jan 22, 2015
@griesemer
Copy link
Contributor

Scanln stops scanning at the newline (or EOF) but otherwise scans space-separated values. There are 0 space-separated values on an empty line (since arbitrary many "empty strings" makes no sense). If you call fmt.Scanln() just like this (w/ no arguments), then you won't get an error since you're not expecting anything. If you call it with more than one argument, than you have to provide an appropriate number of non-empty input values which are space-separated. If you want an empty string, provide an empty string "".

This is working as intended.

Next time, please leave a complete example so the context is clear (a reader has to guess the arguments you may or may not have provided).

Also, next time, please don't use the issue tracker to ask questions - that's what the go-nuts mailing list is for.

@golang golang locked and limited conversation to collaborators Jun 25, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants