2 ms·
Replacing the 3 additions of gapin the loop with a single subtraction (and an increment): void condense_by_removing(char* z_terminated, char char_to_remove)
by dkersten 16y ago
Replacing the 3 additions of gapin the loop with a single subtraction (and an increment):
void condense_by_removing(char* z_terminated, char char_to_remove) {
int offset = 0;
for (; *z_terminated; ++z_terminated) {
if (*z_terminated == char_to_remove) {
++offset;
++z_terminated;
}
if (offset > 0) *(z_terminated - offset) = *z_terminated;
}
*(z_terminated - offset) = 0;
}