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: Scanf rejects \r\n at end of line on Windows #5391

Closed
gopherbot opened this issue May 2, 2013 · 5 comments
Closed

fmt: Scanf rejects \r\n at end of line on Windows #5391

gopherbot opened this issue May 2, 2013 · 5 comments
Milestone

Comments

@gopherbot
Copy link

@gopherbot gopherbot commented May 2, 2013

by xuxinhua1984:

The code:

package main

import (
    "fmt"
)

func main() {
    for i := 0; i < 2; i++ {
        var name string
        fmt.Print("Input Name:")
        n, err := fmt.Scanf("%s", &name)
        fmt.Println(n, err, name)
    }   
}

Build And Run.

Then, I input:golang,and enter,the result is:

Input Name:golang
1 <nil> golang
Input Name:0 unexpected newline

But on linux,the same code, the result is ok:

Input Name:golang
1 <nil> golang
Input Name:golang
1 <nil> golang

The reason is: on windows, The "enter" is "\r\n", but in fmt
package, it is only deal "\n".
@gopherbot

This comment has been minimized.

Copy link
Author

@gopherbot gopherbot commented May 2, 2013

Comment 1 by xuxinhua1984:

When I use fmt.Scanln(&name) or fmt.Scanf("%s\n", &name), it is OK!
@davecheney

This comment has been minimized.

Copy link
Contributor

@davecheney davecheney commented May 25, 2013

Comment 2:

Hello, is there anything actionable in this issue, or may it be closed ?

Status changed to WaitingForReply.

@gopherbot

This comment has been minimized.

Copy link
Author

@gopherbot gopherbot commented Jun 3, 2013

Comment 3 by opnieuw1280:

Hello one should either acknowledge that semantics are OS-dependendent or change
implementation (ASAP!) - I think damage is already done so leaves first option.
The root problem of course is that some OS-s do not have an opaque record structure
for files. (this includes Unix as well as Windows - still rather silly - once details
are visible they are bound to be different )
@rsc

This comment has been minimized.

Copy link
Contributor

@rsc rsc commented Jul 30, 2013

Comment 5:

Labels changed: added priority-later, go1.2maybe, removed priority-triage.

Status changed to Thinking.

@robpike

This comment has been minimized.

Copy link
Contributor

@robpike robpike commented Jul 31, 2013

Comment 6:

This issue was closed by revision 221af5c.

Status changed to Fixed.

@rsc rsc added this to the Go1.2 milestone Apr 14, 2015
@rsc rsc removed the go1.2maybe label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
4 participants
You can’t perform that action at this time.