Working with a custom split function

Report a typo

Bob has been working on a Go program that uses a custom split function ScanFloats to validate float64 input.

Now Bob needs some assistance with his program to set ScanFloats as the Scanner split function and create a for loop that calls the Scan() function to output the scanned data. Please help Bob write the additional required code.

Sample Input 1:

3.14159 1.618 42

Sample Output 1:

3.14159
1.618
42
Write a program in Go
package main

import (
"bufio"
"fmt"
"log"
"os"
"strconv"
)

const FloatPrecision = 64

// Do not delete the ScanFloats() function!
func ScanFloats(data []byte, atEOF bool) (int, []byte, error) {
advance, token, err := bufio.ScanWords(data, atEOF)
if err == nil && token != nil {
_, err = strconv.ParseFloat(string(token), FloatPrecision)
}
return advance, token, err
}

func main() {
scanner := bufio.NewScanner(os.Stdin)
// Set 'ScanFloats' as the split function below
scanner.?(?)

// Write the for loop to scan and then output the scanned data
for ? {
fmt.Println(?)
}
if err := scanner.Err(); err != nil {
log.Println(err)
}
}
___

Create a free account to access the full topic