Here's a function that will strip a list of characters from a string and return the new version:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char *stripchars (char *string, char *list) {
int len = strlen(string), lsz = strlen(list), c = 0, i, j, flag;
char tmp[len+1], *new;
for (i=0;i<len;i++) {
flag = 0;
for (j=0;j<lsz;j++) {
if (string[c] == list[j]) {
flag = 1;
break;
}
}
if (!flag) tmp[i] = string[c];
else { --i; --len; }
c++;
}
tmp[i] = '\0';
new = malloc(strlen(tmp)+1);
strcpy(new,tmp);
return new;
}
int main() {
char s1[] = "a man a plan a canal panama", *s2;
s2 = stripchars(s1, " ");
printf("%s\n%s\n",s1, s2);
free(s2);
return 0;
}