3 ms·
I would use a do-while, because at least one char is always copied: char c; do { c = *src++; *dst++ = c; } while (c != 0);
by layer8 4y ago
I would use a do-while, because at least one char is always copied:
char c;
do
{
c = *src++;
*dst++ = c;
}
while (c != 0);
The post-increment is idiomatic enough in C-based languages that I wouldn’t worry about that.
- bee_rider 4y agoI don’t write much C, but to an outsider like me this is a pretty big improvement. It is a shame post-test loops aren’t more popular, given the similarity to the assembly they output. Seems more mechanically sympathetic. Oh well, at least it is an excuse to whip out the goto.
- layer8 4y agoIn Pascal, you could do repeat ... until c = 0; which might be even clearer for this use case.
- flohofwoe 4y agoI was considering that but had my doubts that people who already find post-increment confusing could handle a do-while loop ;)