3 ms·
A cursory look into the linked github pull request changes made me spot this, and I must admit that never in a million years would I've thought to erase the pos
by YSFEJ4SWJUVU6 9y ago
A cursory look into the linked github pull request changes made me spot this, and I must admit that never in a million years would I've thought to erase the possible endline character of a string returned by getline with this:
line[strcspn(line, "\n")] = 0;
I don't think I'm going to start, either, even if it is a nifty oneliner. Anyway, I've always found this kind of little projects a good sport.
- eplanit 9y agoWise choice.
- YSFEJ4SWJUVU6 9y agoThat's not correct. If the scanned string doesn't contain any of the search string's characters, strcspn will behave like strlen, and the snippet ends up doing effectively nothing. However, the statement is inefficient in what it does (and even then, not the most obvious way to achieve that, which your comment also highlights in a roundabout way).