Created
February 15, 2024 20:56
-
-
Save yakuter/d74659ace1bc596fc3469f57a026ae77 to your computer and use it in GitHub Desktop.
Copy and Movement 10
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"io" | |
"strings" | |
) | |
func main() { | |
reader := strings.NewReader("Test") | |
buf := make([]byte, 8) | |
// Wrong: Assuming exactly 8 bytes will be read | |
n, err := reader.Read(buf) | |
if err != nil { | |
fmt.Println("Failed to read:", err) | |
return | |
} | |
fmt.Printf("Read data: %s\n", string(buf[:n])) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment