Deletes each character in s1 that matches any character in the string s2. - C String

C examples for String:String Function

Description

Deletes each character in s1 that matches any character in the string s2.

Demo Code

#include <stdio.h>

#define MAXLINE 1000//from   w w  w. java2 s .  c  o  m

void squeeze(char s1[], char s2[]);

int main(void)
{
    int len;
    char s1[MAXLINE] = "this is a test";
    char s2[MAXLINE] = "test";

    squeeze(s1, s2);
    printf("Result is %s\n", s1);

    return 0;
}
void squeeze(char s1[], char s2[]){
    int i  = 0, j, k;

    while (s2[i] != '\0') {
        j = 0;
        while (s1[j] != '\0') {
            if (s1[j] == s2[i]) {
                k = j;
                while ((s1[k] = s1[++k]) != '\0')
                    ;
            } else{
                ++j;
            }
            
        }
        ++i;
    }
}

Result


Related Tutorials