Skip to content

Instantly share code, notes, and snippets.

@DeMarko
Created November 7, 2010 04:00
Show Gist options
  • Save DeMarko/665952 to your computer and use it in GitHub Desktop.
Save DeMarko/665952 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
using namespace std;
char * remove_char_from_string(char *input_string, char given_char) {
char * newstring = (char *) calloc(strlen(input_string) + 1, sizeof(char));
strcpy(newstring, input_string);
// pointer to character to be overwritten
char * p;
while(p = strchr(newstring, given_char)) {
strcpy(p, p+1);
}
// null terminate string
newstring[strlen(input_string)] = '\0';
return newstring;
}
int main() {
char str1[] = "shamalamadingdong";
cout << remove_char_from_string(str1, 'm') << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment