Golang fmt.Scanf() function example
package fmt
Scanf scans text read from standard input, storing successive space-separated values into successive arguments as determined by the format. It returns the number of items successfully scanned.
Golang fmt.Scanf() function usage example
package main
import (
"fmt"
)
func main() {
var response int
fmt.Println("This program will activate SkyNet worldwide, are you sure about this?\n")
fmt.Scanf("%c", &response) //<--- here
switch response {
default:
fmt.Println("SkyNet launch aborted!")
case 'y':
fmt.Println("SkyNet launched")
case 'Y':
fmt.Println("SkyNet launched")
}
}
Sample output :
This program will activate SkyNet worldwide, are you sure about this?
y
SkyNet launched
Reference :
Advertisement
Something interesting
Tutorials
+18.4k Golang : Read binary file into memory
+12.4k Golang : Search and extract certain XML data example
+9.9k Golang : Turn string or text file into slice example
+8.7k Golang : Find duplicate files with filepath.Walk
+5.4k Golang : fmt.Println prints out empty data from struct
+15.6k Golang : rune literal not terminated error
+6.9k Golang : Calculate BMI and risk category
+5.8k Golang : Fix opencv.LoadHaarClassifierCascade The node does not represent a user object error
+9.4k Golang : Web(Javascript) to server-side websocket example
+6.5k Golang : Calculate diameter, circumference, area, sphere surface and volume
+8.2k Golang : Get final or effective URL with Request.URL example
+20.2k Golang : Count number of digits from given integer value