@kjk1/

book parse sscanf

Go

No description

fork
loading
Files
  • main.go

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.8123773009677084","path":"main.go","file":{"path":"main.go","content":{"asEncoding":{"base64":"cGFja2FnZSBtYWluCgppbXBvcnQgKAoJImZtdCIKCSJsb2ciCikKCmZ1bmMgbWFpbigpIHsKCS8vIDpzaG93IHN0YXJ0CgkvLyBleHRyYWN0IGludCBhbmQgZmxvYXQgZnJvbSBhIHN0cmluZwoJcyA6PSAiNDggMTIzLjQ1IgoJdmFyIGYgZmxvYXQ2NAoJdmFyIGkgaW50CgluUGFyc2VkLCBlcnIgOj0gZm10LlNzY2FuZihzLCAiJWQgJWYiLCAmaSwgJmYpCglpZiBlcnIgIT0gbmlsIHsKCQlsb2cuRmF0YWxmKCJmaXJzdCBmbXQuU3NjYW5mIGZhaWxlZCB3aXRoICVzXG4iLCBlcnIpCgl9CglmbXQuUHJpbnRmKCJpOiAlZCwgZjogJWYsIGV4dHJhY3RlZCAlZCB2YWx1ZXNcbiIsIGksIGYsIG5QYXJzZWQpCgoJdmFyIGkyIGludAoJXywgZXJyID0gZm10LlNzY2FuZihzLCAiJWQgJWYgJWQiLCAmaSwgJmYsICZpMikKCWlmIGVyciAhPSBuaWwgewoJCWZtdC5QcmludGYoInNlY29uZCBmbXQuU3NjYW5mIGZhaWxlZCB3aXRoICVzXG4iLCBlcnIpCgl9CgoJLy8gOnNob3cgZW5kCn0K"},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package main

import (
	"fmt"
	"log"
)

func main() {
	// :show start
	// extract int and float from a string
	s := "48 123.45"
	var f float64
	var i int
	nParsed, err := fmt.Sscanf(s, "%d %f", &i, &f)
	if err != nil {
		log.Fatalf("first fmt.Sscanf failed with %s\n", err)
	}
	fmt.Printf("i: %d, f: %f, extracted %d values\n", i, f, nParsed)

	var i2 int
	_, err = fmt.Sscanf(s, "%d %f %d", &i, &f, &i2)
	if err != nil {
		fmt.Printf("second fmt.Sscanf failed with %s\n", err)
	}

	// :show end
}