Wednesday, May 13, 2015

str replace



#include<stdio.h>
int main()
{
        char a[]="complete ref book";
        char b[]="ref";
        char c[]="hear";
        char *p,*q,*s,*t,*u,*r;
        p=a;
        q=b;
        r=c;
        u=p;
        s=a;
        int i=0,j=0,count=0,length=3,length1=4;
        while(*p)
        {
                while(*p==*q)
                {
                        p++;
                        q++;
                        count++;
                        if (count == length)
                        {
                                u=p;
                                if(length<length1)
                                {
                                        while(*p)
                                        {
                                                p++;
                                        }
                                        t=p+1;
                                        while(j<length1)
                                        {
                                                while(*p!='f')
                                                {
                                                        *t=*p;
                                                        t--;
                                                        p--;
                                                }
                                                j++;
                                        }
                                }
                                u=u-length;
                                while(i<length1)
                                                                     {
                                        *u=*r;
                                        r++;
                                        u++;
                                        i++;
                                }
                                r=c;
                        }
                }
                q=b;
                p++;
                count=0;
        }
        printf("%s",s);
}

No comments:

Post a Comment