Created
May 27, 2010 15:55
-
-
Save peterc/415975 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 <string.h> | |
void condense_by_removing(char *z_terminated, char char_to_remove); | |
void condense_by_removing(char *z_terminated, char char_to_remove) { | |
int i, j = 0; | |
for (i = 0; i <= strlen(z_terminated); i++) | |
if (z_terminated[i] != char_to_remove) | |
z_terminated[j++] = z_terminated[i]; | |
} | |
int main() { | |
char s[] = "hello world"; | |
condense_by_removing(s, 'l'); | |
printf("%s\n", s); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
include <stdio.h>
// Prototype
void condense_by_removing(char *z_terminated, char char_to_remove);
// BEGIN
main() {
char test_string[] = "Hello, World. This is a test.";
printf("\n\nOrig String: %s", test_string);
condense_by_removing(test_string, ' ' );
printf("\n\nNew String: %s\n\n", test_string);
return 0;
}
// Function
void condense_by_removing(char _z_terminated, char char_to_remove) {
char *new_string = z_terminated;
while(_z_terminated != '\0') {
if(*z_terminated != char_to_remove) *new_string++ = *z_terminated;
*z_terminated++;
}
*new_string = '\0';
}