A Collection of Code Snippets in as Many Programming Languages as Possible
This project is maintained by TheRenegadeCoder
Welcome to the Longest Word in Odin page! Here, you'll find the source code for this program as well as a description of how the program works.
package main
import "core:fmt"
import "core:strings"
import "core:os"
main :: proc() {
if len(os.args) != 2 {
usage()
return
}
text := os.args[1]
get_longest_word(text)
}
get_longest_word :: proc (words: string) -> int {
if len(words) == 0 {
usage()
return 0
}
cleaned, _ := strings.replace_all(words, "\t", " ")
cleaned, _ = strings.replace_all(cleaned, "\r", " ")
cleaned, _ = strings.replace_all(cleaned, "\n", " ")
string_split := strings.split(cleaned, " ")
count := 0
for word in string_split {
if len(word) > count {
count = len(word)
}
}
fmt.println(count)
return count
}
usage :: proc() {
fmt.eprintln("Usage: please provide a string")
}
Longest Word in Odin 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.