Longest Word in Odin

Published on 03 August 2024 (Updated: 03 August 2024)

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.

Current Solution

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.

How to Implement the Solution

No 'How to Implement the Solution' section available. Please consider contributing.

How to Run the Solution

No 'How to Run the Solution' section available. Please consider contributing.