#what is the difference ?

52 messages · Page 1 of 1 (latest)

serene patrol
#
package main

import ("fmt";"os")

func main() {
    file, _ := os.Open("test.txt")

    var one string
    var two string

    fmt.Fscan(file, &one, &two)

    fmt.Println(one, two)

}

fmt.fscan and fmt.fscanln produces the same output :

name unknown

where is the difference between these two functions ????

balmy marlin
gray dirgeBOT
#

    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.

serene patrol
#

؟

balmy marlin
#

Fscanln is similar to Fscan, but stops scanning at a newline and after the final item there must be a newline or EOF.

serene patrol
#

it doesn't

#

name unknown

#

is all what is in the file

balmy marlin
#

how the file looks like?

serene patrol
#

fmt.fscanln should stop at the newline

#

let me show you

queen hemlock
serene patrol
queen hemlock
serene patrol
#

i replied to her/him by it doesn't

balmy marlin
#

newLineFscanln stops on new line

serene patrol
balmy marlin
#

can you show the whole IDE screen?

serene patrol
#

sure

#

i tried using cmd

#

is there anything wrong with the compiler ???????

balmy marlin
#

thats strange

#

im gonna run windows VM, gimme 10-20 minutes to check it

serene patrol
balmy marlin
#

can you run go version in cmd?

serene patrol
balmy marlin
balmy marlin
serene patrol
#
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)
}
balmy marlin
#
s := "name unknown"
file := strings.NewReader(s)

// test.txt:
// name unknown
file, _ := os.Open("test.txt")```

thats almost the same
#

in this context

serene patrol
#

with files the issue occures

balmy marlin
#

add new line to the file

#

and use fmt.Fscanln

serene patrol
#
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

serene patrol
#

and i get the same issue

balmy marlin
#
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```
serene patrol
#

???????????????

#

i swear to god i get the same output i used 4 editors