diff options
Diffstat (limited to '')
-rw-r--r-- | pkg/pointer/intput-output.go | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/pkg/pointer/intput-output.go b/pkg/pointer/intput-output.go index ac58d44..6a2423a 100644 --- a/pkg/pointer/intput-output.go +++ b/pkg/pointer/intput-output.go @@ -2,37 +2,42 @@ package pointer import ( "fmt" - "log" "os" ) var defaultInputLastChar *int = nil -func DefaultCharacterInput() int { +func DefaultCharacterInput() (int, error) { if defaultInputLastChar != nil { c := *defaultInputLastChar defaultInputLastChar = nil - return c + return c, nil } b := make([]byte, 1) i, err := os.Stdin.Read(b) if err != nil { - log.Fatalf("Error in DefaultCharacterInput { b: %c, i: %d, err: %+v }", b[0], i, err) + return 0, fmt.Errorf("Error in DefaultCharacterInput { b: %c, i: %d, err: %w }", b[0], i, err) } - return int(b[0]) + return int(b[0]), nil } -func DefaultDecimalInput() int { +func DefaultDecimalInput() (int, error) { var v int for { - c := DefaultCharacterInput() + c, err := DefaultCharacterInput() + if err != nil { + return 0, err + } if c >= '0' && c <= '9' { v = c - '0' break } } for { - c := DefaultCharacterInput() + c, err := DefaultCharacterInput() + if err != nil { + break + } if c >= '0' && c <= '9' { v = v*10 + c - '0' } else { @@ -40,7 +45,7 @@ func DefaultDecimalInput() int { break } } - return v + return v, nil } func DefaultCharacterOutput(c int) { |