How do I give input to a Tcl script 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With