4 ms·
for (int i = 0; i < strlen(s); i++) { s[i] ^= 0x20; }
by commandlinefan 2y ago
for (int i = 0; i < strlen(s); i++) {
s[i] ^= 0x20;
}
- vardump 2y agoSurely you meant: s[i] &= ~0x20; We're talking about converting to upper case after all! As an added benefit, every space character (0x20) is now a NUL byte!
- account42 2y agoFree strtok!
- calibas 2y agoThank you for this universal approach. I can now toggle capitalization on/off for any character, instead of just being limited to alphabetic ones! Jokes aside, I was kinda hoping for a good answer that doesn't rely on a Windows API or an external library, but I'm not sure there is one. It's a rather complex problem when you account for more than just ASCII and the English language.
- TZubiri 2y agoNext up, check out our vector addition implementation of Hello+World. Spoiler alert, the result is Zalgo