本文整理汇总了Golang中fmt.Sscanln函数的典型用法代码示例。如果您正苦于以下问题:Golang Sscanln函数的具体用法?Golang Sscanln怎么用?Golang Sscanln使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Sscanln函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: parseLine
// Parse an individual line from Linux's /proc/net/dev.
func (nic *NICSampler) parseLine(line string) (err error) {
var dev string
var rx_byte, rx_pkt, rx_err, rx_drop uint64
var rx_fifo, rx_frame, rx_comp, rx_mcast uint64
var tx_byte, tx_pkt, tx_err, tx_drop uint64
var tx_fifo, tx_coll, tx_carr, tx_comp uint64
if strings.Contains(line, "|") {
return
}
_, err = fmt.Sscanln(line,
&dev,
&rx_byte, &rx_pkt, &rx_err, &rx_drop,
&rx_fifo, &rx_frame, &rx_comp, &rx_mcast,
&tx_byte, &tx_pkt, &tx_err, &tx_drop,
&tx_fifo, &tx_coll, &tx_carr, &tx_comp)
if err != nil {
return
}
dev = dev[0 : len(dev)-1]
if strings.HasPrefix(dev, "lo") {
return
}
nic.sink.Write("net",
dev,
rx_byte, rx_pkt, rx_err, rx_drop,
tx_byte, tx_pkt, tx_err, tx_drop)
return
}
开发者ID:codeslinger,项目名称:monitor,代码行数:30,代码来源:standard.go
示例2: Scanln
func (fakeUi *FakeUi) Scanln(args ...interface{}) (int, error) {
fakeUi.Args = args
fmt.Sscanln(fakeUi.UserInput, args[0])
return fakeUi.ScanlnRc, fakeUi.ScanlnErr
}
开发者ID:cloudfoundry-community,项目名称:bosh-softlayer-tools,代码行数:7,代码来源:fake_ui.go
示例3: GetOwner
// Who owns the lockfile?
func (l Lockfile) GetOwner() (*os.Process, error) {
name := string(l)
// Ok, see, if we have a stale lockfile here
content, err := ioutil.ReadFile(name)
if err != nil {
return nil, err
}
var pid int
_, err = fmt.Sscanln(string(content), &pid)
if err != nil {
return nil, ErrInvalidPid
}
// try hard for pids. If no pid, the lockfile is junk anyway and we delete it.
if pid > 0 {
p, err := os.FindProcess(pid)
if err != nil {
return nil, err
}
return p, isProcessAlive(p)
} else {
return nil, ErrInvalidPid
}
panic("Not reached")
}
开发者ID:kovetskiy,项目名称:lockfile,代码行数:28,代码来源:lockfile.go
示例4: boxFromString
// boxFromString returns the box defined by a string of the form "x y w h id".
func boxFromString(in string) (b box, err error) {
_, err = fmt.Sscanln(in, &b.x, &b.y, &b.w, &b.l, &b.id)
if b == emptybox {
return b, errEmpty
}
if b.w == 0 && b.l == 0 {
return b, errZeroBox
}
return
}
开发者ID:billyboar,项目名称:GCSolutions,代码行数:11,代码来源:pallet.go
示例5: main
func main() {
str := "34 343 245"
var a, b, c int
fmt.Sscan(str, &a, &b, &c)
fmt.Println(a, b, c)
fmt.Sscanf(str, "%d %d %d", &a, &b, &c)
fmt.Println(a, b, c)
fmt.Sscanln(str, &a, &b, &c)
fmt.Println(a, b, c)
}
开发者ID:cwen-coder,项目名称:study-gopkg,代码行数:10,代码来源:Sscan.go
示例6: readLockfile
func readLockfile(path string) (pid int, err error) {
d, err := ioutil.ReadFile(path)
if os.IsNotExist(err) {
return 0, nil
}
if err != nil {
return 0, err
}
if _, err := fmt.Sscanln(string(d), &pid); err != nil {
return 0, ErrReadingLockfile
}
return pid, nil
}
开发者ID:nicolasleger,项目名称:heroku-cli,代码行数:13,代码来源:lock.go
示例7: main
func main() {
cgreader.RunStaticProgram(
"../../input/ascii_4.txt",
"../../output/ascii_4.txt",
true,
func(input <-chan string, output chan string) {
var width, height int
var text string
fmt.Sscanln(<-input, &width)
fmt.Sscanln(<-input, &height)
fmt.Sscanln(<-input, &text)
text = strings.ToUpper(text)
ascii := make([]string, height)
for i := 0; i < height; i++ {
ascii[i] = <-input
}
lines := make([]string, height)
for _, char := range text {
character := int(char) - 65
if character < 0 || character > 26 {
character = 26
}
for i := range lines {
position := character * width
lines[i] += ascii[i][position : position+width]
}
}
for _, line := range lines {
output <- fmt.Sprintln(line)
}
})
}
开发者ID:shawshining,项目名称:Codingame,代码行数:37,代码来源:ascii_art.go
示例8: Update
// Update from /proc/stst
func (s *procStat) Update() (st procStat, err error) {
data, err := readFile(filepath.Join(PROC_DIR, "stat"))
if err != nil {
log.Println(err)
return
}
var ig string
fmt.Sscanln(string(data), &ig, &s.User, &s.Nice, &s.Sys, &s.Idle, &s.Iowait, &s.Irq, &s.Softirq)
st = *s
// Cpu Count
re, _ := regexp.Compile("\ncpu[0-9]")
s.Ncpu = len(re.FindAllString(string(data), 100))
s.timeStamp = time.Now()
return
}
开发者ID:mehulsbhatt,项目名称:monitor,代码行数:16,代码来源:monitor.go
示例9: main
func main() {
reader := bufio.NewReader(os.Stdin)
fmt.Print("Enter text: ")
text, _ := reader.ReadString('\n')
fmt.Println(text)
fmt.Println("Enter text: ")
text2 := ""
fmt.Scanln(text2)
fmt.Println(text2)
ln := ""
fmt.Sscanln("%v", ln)
fmt.Println(ln)
}
开发者ID:voltron42,项目名称:rpgPractice,代码行数:15,代码来源:io.go
示例10: scanPidLine
func scanPidLine(content []byte) (int, error) {
if len(content) == 0 {
return 0, ErrInvalidPid
}
var pid int
if _, err := fmt.Sscanln(string(content), &pid); err != nil {
return 0, ErrInvalidPid
}
if pid <= 0 {
return 0, ErrInvalidPid
}
return pid, nil
}
开发者ID:nightlyone,项目名称:lockfile,代码行数:15,代码来源:lockfile.go
示例11: toRat
// toRat converts a Value to rat. A str can be converted to a rat if it can be
// parsed. A rat is returned as-is. Other types of values cannot be converted.
func toRat(v Value) (rat, error) {
switch v := v.(type) {
case rat:
return v, nil
case str:
r := big.Rat{}
_, err := fmt.Sscanln(string(v), &r)
if err != nil {
return rat{}, fmt.Errorf("%s cannot be parsed as rat", v.Repr())
}
return rat{&r}, nil
default:
return rat{}, errOnlyStrOrRat
}
}
开发者ID:earneet,项目名称:elvish,代码行数:17,代码来源:value.go
示例12: str
func str() {
var a int
var b int
log.Printf("a: %d, b: %d", a, b)
fmt.Sscan("20\n20", &a, &b)
log.Printf("a: %d, b: %d", a, b)
fmt.Sscanf("(15, 30)", "(%d, %d)", &a, &b)
log.Printf("a: %d, b: %d", a, b)
// Will not go past the newline, only scans a
fmt.Sscanln("10\n10", &a, &b)
log.Printf("a: %d, b: %d", a, b)
}
开发者ID:johnvilsack,项目名称:golang-stuff,代码行数:15,代码来源:scanning.go
示例13: getSystemUptime
// Returns system uptime as time.Duration.
func getSystemUptime() (uptime time.Duration, err error) {
buf, err := ioutil.ReadFile("/proc/uptime")
if err != nil {
return uptime, err
}
var up, idle float64
n, err := fmt.Sscanln(string(buf), &up, &idle)
if err != nil {
return uptime, err
}
if n != 2 {
return uptime, errors.New("failed parsing /proc/uptime")
}
uptime = time.Duration(up) * time.Second
return uptime, nil
}
开发者ID:0987363,项目名称:zfswatcher,代码行数:18,代码来源:osutil_linux.go
示例14: main
func main() {
scanner := bufio.NewScanner(os.Stdin)
timetable := readTimetable(scanner)
var departureStation, arrivalStation, departureTime uint32
for scanner.Scan() {
if len(scanner.Text()) == 0 {
os.Exit(0)
} else {
_, err := fmt.Sscanln(scanner.Text(), &departureStation, &arrivalStation, &departureTime)
if err != nil {
panic(err)
}
timetable.compute(departureStation, arrivalStation, departureTime)
}
}
}
开发者ID:brechtvdv,项目名称:csa-challenge,代码行数:18,代码来源:csa.go
示例15: GetOwner
// Who owns the lockfile?
func (l Lockfile) GetOwner() (*os.Process, error) {
name := string(l)
// Ok, see, if we have a stale lockfile here
content, err := ioutil.ReadFile(name)
if err != nil {
return nil, err
}
var pid int
_, err = fmt.Sscanln(string(content), &pid)
if err != nil {
return nil, err
}
// try hard for pids. If no pid, the lockfile is junk anyway and we delete it.
if pid > 0 {
p, err := os.FindProcess(pid)
if err != nil {
return nil, err
}
err = p.Signal(os.Signal(syscall.Signal(0)))
if err == nil {
return p, nil
}
errno, ok := err.(syscall.Errno)
if !ok {
return nil, err
}
switch errno {
case syscall.ESRCH:
return nil, ErrDeadOwner
case syscall.EPERM:
return p, nil
default:
return nil, err
}
} else {
return nil, ErrInvalidPid
}
panic("Not reached")
}
开发者ID:mlafeldt,项目名称:remote_syslog2,代码行数:44,代码来源:lockfile.go
示例16: main
func main() {
reader := bufio.NewReader(os.Stdin)
tString, _ := reader.ReadString('\n')
t, _ := strconv.Atoi(tString)
for i := 0; i < t; i++ {
nString, _ := reader.ReadString('\n')
n, _ := strconv.Atoi(nString)
}
fmt.Println("Enter text: ")
text2 := ""
fmt.Scanln(text2)
fmt.Println(text2)
ln := ""
fmt.Sscanln("%v", ln)
fmt.Println(ln)
fmt.Println("Hello World!")
}
开发者ID:enricodangelo,项目名称:exercises-in-style,代码行数:19,代码来源:01-chandu_and_his_girlfriend.go
示例17: SPrintScanPrac12
func SPrintScanPrac12() {
var num1 int
var num2 float32
var s string
input1 := "1\n1.1\nHello"
n, _ := fmt.Sscan(input1, &num1, &num2, &s)
fmt.Println("입력 개수 : ", n)
fmt.Println(num1, num2, s)
input2 := "1 1.1 Hello"
n, _ = fmt.Sscanln(input2, &num1, &num2, &s)
fmt.Println("입력 개개 : ", n)
fmt.Println(num1, num2, s)
input3 := "1,1.1,Hello"
n, _ = fmt.Sscanf(input3, "%d,%f,%s", &num1, &num2, &s)
fmt.Println("입력 갯수 : ", n)
fmt.Println(num1, num2, s)
}
开发者ID:cdragonkim,项目名称:GoRoom,代码行数:20,代码来源:sPrintScanPrac1.go
示例18: GetOffset
// Read in the offsets for an IP from a file. File name == IP address.
func GetOffset(addr string) (HostOffset, os.Error) {
data, err := ioutil.ReadFile(addr)
o := HostOffset{}
if err != nil {
return o, err
}
str := string(data)
_, err = fmt.Sscanln(str,
&o.Year.Op, &o.Year.Value,
&o.Month.Op, &o.Month.Value,
&o.Day.Op, &o.Day.Value,
&o.Hour.Op, &o.Hour.Value,
&o.Minute.Op, &o.Minute.Value,
&o.Second.Op, &o.Second.Value)
return o, err
}
开发者ID:sysprv,项目名称:time-server,代码行数:21,代码来源:time-server.go
示例19: main
func main() {
var num1 int
var num2 float32
var s string
input1 := "1\n1.1\nHello"
n, _ := fmt.Sscan(input1, &num1, &num2, &s) // 공백, 개행 문자로 구분된 문자열에서 입력을 받음
fmt.Println("입력 개수:", n) // 입력 개수: 3
fmt.Println(num1, num2, s) // 1 1.1 Hello
input2 := "1 1.1 Hello"
n, _ = fmt.Sscanln(input2, &num1, &num2, &s) // 공백으로 구분된 문자열에서 입력을 받음
fmt.Println("입력 개수:", n) // 입력 개수: 3
fmt.Println(num1, num2, s) // 1 1.1 Hello
input3 := "1,1.1,Hello"
n, _ = fmt.Sscanf(input3, "%d,%f,%s", &num1, &num2, &s) // 문자열에서 형식을 지정하여 입력을 받음
fmt.Println("입력 개수:", n) // 입력 개수: 3
fmt.Println(num1, num2, s) // 1 1.1 Hello
}
开发者ID:jemoonkim,项目名称:golangbook,代码行数:20,代码来源:Sscan.go
示例20: main
func main() {
var s1, s2, s3 string
s1 = fmt.Sprint(1, 1.1, "Kinow")
fmt.Println(s1)
s2 = fmt.Sprintln(1, 1.1, "Kinow")
fmt.Println(s2)
s3 = fmt.Sprintf("%d %f %s\n", 1, 1.1, "Kinow")
fmt.Println(s3)
var num1 int
var num2 float32
var s string
input1 := "1\n1.1\nHello"
n, _ := fmt.Sscan(input1, &num1, &num2, &s)
fmt.Println("입력개수:", n)
fmt.Println(num1, num2, s)
num1 = 0
num2 = 0
s = ""
input2 := "1 1.1 Hello"
n, _ = fmt.Sscanln(input2, &num1, &num2, &s)
fmt.Println("입력개수:", n)
fmt.Println(num1, num2, s)
num1 = 0
num2 = 0
s = ""
input3 := "1,1.1,Hello World"
n, _ = fmt.Sscanf(input3, "%d,%f,%s", &num1, &num2, &s)
fmt.Println("입력개수:", n)
fmt.Println(num1, num2, s)
}
开发者ID:kangaukju,项目名称:golang,代码行数:40,代码来源:sprint.go
注:本文中的fmt.Sscanln函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论