Remove char from string - C String

C examples for String:String Function

Description

Remove char from string

Demo Code

#include <stdio.h>

//delete all c from s
void squeeze(char s[], int c){
    int i, j;//from w  ww .  j  a va2 s. c om

    for (i = j = 0; s[i] != '\0'; i++)
        if (s[i] != c)
            s[j++] = s[i];
    s[j] = '\0';
}

int main(){
    char buf[1000];

    while (fgets(buf, sizeof buf, stdin) != NULL) {
        squeeze(buf, 'e');
        squeeze(buf, 't');
        printf("%s", buf);
    }
    return 0;
}

Result


Related Tutorials