Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

For extra performance, use strchr to find the first char_to_remove.

  /* Find the first character to remove */
  /* This doubles the performance when there are no
     remove characters, I assume because it uses a
     builtin and because I don't do unneeded writes. */
  src = strchr(z_terminated, char_to_remove);
  if (src == NULL)
    return;

  /* src is the position in the old string, with
       the possible characters to remove.
     dest is the end position of the new string,
       where non-removed characters are added */
  dest = src++;

  for (;;) {
    /* Skip additional remove characters */
    while (*src == char_to_remove)
      src++;

    /* Copy (including copying the terminal NUL) */
    if (! (*dest++ = *src++)) {
      /* copied a NUL - end of string */
      break;
    }
  }


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: