Kodewick
Start learning →
Mini challenge←→0 / 70

Longest word

#065Mini challengeStringsConditions6 min

Postcard boxes are small, so first check how long the longest word is. Write longest_word(s) to return the number of letters in the longest word of s. Words are separated by spaces (maybe more than one); an empty string gives 0.

Examples
longest_word("see you at the beach")→5
longest_word("")→0
The functionint longest_word(const char *s)
main.c
int longest_word(const char *s) {
    int now = 0;
    int best = 0;
    for (int i = 0; s[i] != '\0'; i++) {
        // your code here: a space sets now to 0; otherwise add 1 to now and keep it in best if bigger
    }
    return best;
}
Ctrl + Enter runs too
Result

Run tries the examples. When they look right, Submit.