fmt.Scanf Introduction

From the fmt package; the Scanf function is used to read input from stdin. When you run this snippet of code the main() function will wait for user input a string, a number, and a second string. Which it puts into variables, and then uses to print some information.

Scanf woul be used when you want to write a command line program that requires user input during the running process.

var s1   string
var s2   string
var rint int

_, err := fmt.Scanf("%s %d %s", &s1, &rint, &s2)
if err != nil {

fmt.Println("this is the first string from the commandline: ", s1)
fmt.Println("this is the first int from the commandline: ", rint)
fmt.Println("this is the second string from the commandline: ", s2)
fmt.Scanf Introduction by  
  go  programming  golang  print 
Like what you read? Share it:
  Facebook   Twitter   Google+