Scanning letter-by-letter

Report a typo

Bruno wants to create a Go program that takes a string as an input and then outputs the string letter by letter. He has already created a Scanner and written a part of the code. However, his program prints the string word-by-word instead of letter-by-letter.

Please help Bruno use the correct split function for the Scanner, so his program can print the string letter by letter.

Sample Input 1:

Hello

Sample Output 1:

H
e
l
l
o
Write a program in Go
package main

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

func main() {
scanner := bufio.NewScanner(os.Stdin)
// What split function allows us to read character by character?
scanner.Split(bufio.ScanWords)

for scanner.Scan() {
c := scanner.Text()
fmt.Println(c)
}
}
___

Create a free account to access the full topic