Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

why fmt.Scanf("%s", &name) print the previous value

I make this code for learning:-

package main

import (
    "fmt"
    "strconv"
)

func main() {

    for {
        name := ""
        fmt.Print("Enter : ")
        fmt.Scanf("%s", &name)
        b1, _ := strconv.ParseBool(name)
        fmt.Printf("%T, %v\n", b1, b1)
    }

}

output:

Enter : True

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

bool, true

Enter : bool, false

Enter :

why there is extra "Enter : bool, false" line?

>Solution :

I assume you’re using some IDE.

sometimes they mess up the console output, try to run directly from native terminal instead. Or use vscode.

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading