Selective reading

Report a typo

Below is a Go program that has an initialized variable reader.

Your task is to use the reader.Seek() method to move the position of the reader to the last 7 bytes, and then use the reader.Read() method to read and print the last 7 bytes of the textSource.

Write a program in Go
package main

import (
"fmt"
"io"
"strings"
)

const textSource = "Supercalifragilisticexpialidocious"

// nolint: gomnd // DO NOT delete this comment!
func main() {
fmt.Println("full text:", textSource)

reader := strings.NewReader(textSource)

p := make([]byte, 7)
// Move the position of the `reader` to the last 7 bytes below:
_, err := reader.Seek(??, ??)
if err != nil {
return
}

if _, err := reader.Read(p); err != nil {
fmt.Println(err)
}
fmt.Print("selected: ", string(p), " ")
}
___

Create a free account to access the full topic