Comment

Comment by jstanley

The random idiom I got was:

> Idiom #137 Check if string contains only digits

> Set boolean b to true if string s contains only characters in range '0'..'9', false otherwise.

    char b = 0;
    for (int i = 0; i < strlen(s); i++) {
        if (! (b = (s[i] >= '0' && s[i] <= '9')))   break;
    }
I appreciate the funny assignment-and-test-and-early-break in one (although I'd hardly say it's idiomatic), but I could do without the quadratic strlen().
parent jstanley 5 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton