Handling stdin in Go: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 6: Line 6:
cnt, err := fmt.Scan(&s)
cnt, err := fmt.Scan(&s)
fmt.Printf("input line: %s, cnt: %d, error: %s\n", s, cnt, err)
fmt.Printf("input line: %s, cnt: %d, error: %s\n", s, cnt, err)
</syntaxhighlight>
=<tt>fmt.Scanf()</tt>=
<syntaxhighlight lang='go'>
var f float
cnt, err := fmt.Scanf("%f", &f)
</syntaxhighlight>
</syntaxhighlight>

Revision as of 01:16, 23 August 2023

Internal

fmt.Scan()

var s string
cnt, err := fmt.Scan(&s)
fmt.Printf("input line: %s, cnt: %d, error: %s\n", s, cnt, err)

fmt.Scanf()

var f float
cnt, err := fmt.Scanf("%f", &f)