Created
November 7, 2010 04:00
-
-
Save DeMarko/665952 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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