Golang : How to read integer value from standard input ?
Reading integer value from standard input in Golang is fairly simple with fmt.Scanf function. The code below demonstrate how to capture integer value from the standard input.
package main
import (
"fmt"
)
func main() {
var i int
fmt.Println("Enter an integer value : ")
_, err := fmt.Scanf("%d", &i)
if err != nil {
fmt.Println(err)
}
fmt.Println("You have entered : ", i)
}
See also : Golang : How to read float value from standard input ?
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+7.7k Golang : Another camera capture GUI application with GTK and OpenCV
+10.7k Golang : Secure file deletion with wipe example
+10.4k Golang : How to use if, eq and print properly in html template
+9.1k Golang : Check a web page existence with HEAD request example
+10k Golang : Sieve of Eratosthenes algorithm
+19.9k Golang : Clean up null characters from input data
+9.4k Golang : cannot assign type int to value (type uint8) in range error
+8.6k Golang : Find correlation coefficient example
+4.7k How to check with curl if my website or the asset is gzipped ?
+7.6k Golang : Count leading or ending zeros(any item of interest) example
+27.6k Golang : Detect (OS) Operating System
+9.8k Golang : Get local time and equivalent time in different time zone