#what is the difference ?
52 messages · Page 1 of 1 (latest)
func Fscanln(r io.Reader, a ...any) (n int, err error)
Fscanln is similar to Fscan, but stops scanning at a newline and after the final item there must be a newline or EOF.
؟
Fscanln is similar to Fscan, but stops scanning at a newline and after the final item there must be a newline or EOF.
how the file looks like?
What doesn't what
she / he said fmt.fscanln stops reading at the newline character
Or the end of file yes
i replied to her/him by it doesn't
can you show the whole IDE screen?
ok my mate
can you run go version in cmd?
i would try to create a new folder, copy the content of the playground into a new main.go in that folder and then run
have you tried it with a file ?
package main
import ("fmt";"os")
func main() {
file,_ := os.Open("test.txt")
var one string
var two string
fmt.Fscanln(file, &one, &two)
fmt.Println(one, two)
}
s := "name unknown"
file := strings.NewReader(s)
// test.txt:
// name unknown
file, _ := os.Open("test.txt")```
thats almost the same
in this context
not the same
with files the issue occures
package main
import "fmt"
import "strings"
func main() {
//file, _ := os.Open("test.txt")
file := strings.NewReader("hello world")
var one string
var two string
fmt.Fscan(file, &one, &two)
fmt.Println(one, two)
}
same thing
package main
import (
"fmt"
"os"
)
func spaceFscan() {
r, _ := os.Open("space.txt")
var one string
var two string
fmt.Fscan(r, &one, &two)
fmt.Println(one, two)
}
func newLineFscan() {
r, _ := os.Open("new_line.txt")
var one string
var two string
fmt.Fscan(r, &one, &two)
fmt.Println(one, two)
}
func newLineFscanln() {
r, _ := os.Open("new_line.txt")
var one string
var two string
fmt.Fscanln(r, &one, &two)
fmt.Println(one, two)
}
func spaceFscanln() {
r, _ := os.Open("space.txt")
var one string
var two string
fmt.Fscanln(r, &one, &two)
fmt.Println(one, two)
}
func main() {
spaceFscan()
spaceFscanln()
newLineFscan()
newLineFscanln()
}
space.txt:
name unknown```
new_line.txt:
```txt
name
unknown```
the same result as with https://go.dev/play/p/ogArCz9dMNI
