Showing posts with label STRING MASKING. Show all posts
Showing posts with label STRING MASKING. Show all posts

Wednesday, 4 July 2012

String Masking : Given a string"S" and we have to remove a an occurance of a small string "M" from there.


Input:
KUMAR
UM

Output:
KAR



#include<stdio.h>
#include<string.h>
int str_com(char K[20],int i,int m,char M[10])
{
    int k=0;
    for(k=0;k<m;k++)
        if(K[i+k]!=M[k])
            break;
    if(k==m)
        return 1;
    return 0;
}

int main()
{
    char S[20],M[10];
    int i,j=0,l,m,k,flage;
    gets(S);
    gets(M);
    l=strlen(S);
    m=strlen(M);
    for(i=0;i<l;i++)
    {
        if(S[i]!=M[0])
            S[j++]=S[i];
        else
            if( str_com(S,i,m,M) )
                i+=m-1;
            else S[j++]=S[i];
    }
    S[j]=NULL;
    printf("< %s >",S);
return 0;
}