String with spaces

My error Scanln is called with multiple arguments and each should be separated by spaces

fmt.Scanln(&a, &b, &c) and if you write “Home sweet home” will a == “Home”, b == “sweet” and c == “home”. You could use Scanner from bufio instead

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {

	scanner := bufio.NewScanner(os.Stdin)
	fmt.Print("> ")
	if scanner.Scan() {
		fmt.Printf("You wrote \"%s\"\n", scanner.Text())
	}
}

and now you could also loop and get each line you write

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {

	scanner := bufio.NewScanner(os.Stdin)
	fmt.Print("> ")
	for scanner.Scan() {
		fmt.Printf("You wrote \"%s\"\n", scanner.Text())
		fmt.Print("> ")
	}
}
1 Like