A Collection of Code Snippets in as Many Programming Languages as Possible
This project is maintained by TheRenegadeCoder
Welcome to the Longest Word in Tcl page! Here, you'll find the source code for this program as well as a description of how the program works.
proc usage {} {
puts stderr {Usage: please provide a string}
exit 1
}
proc longestWordLength {s} {
set s [string trim $s]
if {$s eq ""} { usage }
set maxLen 0
set curLen 0
set len [string length $s]
for {set i 0} {$i < $len} {incr i} {
set ch [string index $s $i]
if {[string is space $ch]} {
if {$curLen > $maxLen} { set maxLen $curLen }
set curLen 0
} else {
incr curLen
}
}
if {$curLen > $maxLen} { set maxLen $curLen }
return $maxLen
}
if {$argc != 1} { usage }
set input [lindex $argv 0]
if {[string trim $input] eq ""} { usage }
puts [longestWordLength $input]
Longest Word in Tcl was written by:
If you see anything you'd like to change or update, please consider contributing.
No 'How to Implement the Solution' section available. Please consider contributing.
No 'How to Run the Solution' section available. Please consider contributing.