我希望在使用 sscanf 处理字符串时忽略特定字段。
sscanf 的手册页说
An optional '*' assignment-suppression character: scanf() reads input as directed by the conversion specification, but discards the input. No corresponding pointer argument is required, and this specification is not included in the count of successful assignments returned by scanf().
尝试在 Golang 中使用它,忽略第三个字段:
if c, err := fmt.Sscanf(str, " %s %d %*d %d ", &iface.Name, &iface.BTx, &iface.BytesRx); err != nil || c != 3 {
编译正常,但在运行时 err 设置为:
bad verb %* for integer
Golang doco 没有特别提到 %* 转换规范,但它确实说,
Package fmt implements formatted I/O with functions analogous to C's printf and scanf.
它并不表示 %* 没有实现,所以......我做错了吗?或者它只是被悄悄地忽略了?...但是,为什么它会编译?