Skip to content

Instantly share code, notes, and snippets.

@iamarkdev
Created December 1, 2016 11:59
Show Gist options
  • Save iamarkdev/a3171ace582bcb25afa19fe73cb21ed7 to your computer and use it in GitHub Desktop.
Save iamarkdev/a3171ace582bcb25afa19fe73cb21ed7 to your computer and use it in GitHub Desktop.
#include <stdio.h>
// remove all characters in string[] that occur in remove[]
void squeeze(char string[], char remove[]) {
int i, x;
for (i = x = 0; string[i] != '\0'; i++) {
int removeChar = 0;
for (int j = 0; remove[j] != '\0'; j++) {
if (string[i] == remove[j]) {
removeChar = 1;
break;
}
}
if (!removeChar) {
string[x++] = string[i];
}
}
string[x] = '\0';
}
int main() {
char string[] = "Something about a fox";
squeeze(string, "something a");
printf("%s\n", string);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment