User_Input_in_Go

command
v0.0.0-...-2113960 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 7, 2022 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

User Input in Go Used to accept text input from the user.

Syntax stores space separated values into successive arguments var storageVariable variableType fmt.Scan(&storageVariable) //assuming fmt is imported

reads line all in one go reader := bufio.NewReader(os.Stdin) //create new reader, assuming bufio imported var storageString string storageString, _ := reader.ReadString('\n')

Notes The Scan function is part of "fmt", so make sure that package is imported. Fmt also comes with Scanf (for specifying string formatting) and Scanln (for scanning until the end of the line). The Scan functions store to a pointer variable.

The scan function itself returns the number of successfully scanned items and if necessary, an error (in that order). It is good practice to error check when using the Scan functions[Scan, Scanf, Scanln].

The Scan functions are used for splitting space-delimited tokens, whereas the reader is used to read full lines.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL