开发者

Input from keyboard in Tcl

How do I give input to a Tcl s开发者_高级运维cript through the keyboard? Is there any thing like scanf() in C?


The gets command is probably what you want.

set data [gets stdin]
# or
set numchars [gets stdin data]

The scan command can be used to parse the input similar to how scanf does with C. It uses the format: scan string format ?varName varName ...?

Thus, to parse an input like "5 cats" to individual variables:

set data [gets stdin]
scan $data "%d %s" myint mystring

Edit: Added more information from Colin's comment.


puts -nonewline "Enter your name: "
flush stdout
set name [gets stdin]

puts "Hello $name"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜