I want to Delete every occurrences of Pattern in String. But What's the problem? Please help with the following C Code.

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
char* SUBSTRING(char *STRING,int POSITION,int LENGTH);
main()
{
    char STRING[100],PATTERN[90];
    int X,P;
    printf("(Input)Enter string & pattern with space between them: ");
    scanf("%s%s",STRING,PATTERN);
    X=INDEX(STRING,PATTERN);
    P=strlen(PATTERN);
    printf("Output: %d\n",X);
    while(X!=0)
    {
        strcpy(STRING,SUBSTRING(STRING,X,P));
        X=INDEX(STRING,PATTERN);

    }
    printf("\nOutput: %d\n",X);
    printf("%s",STRING);

}
int INDEX(char STRING[],char PATTERN[])
{
    int K=1,L=0,S,R,IND, MAX=S-R+1;
    S=strlen(STRING);
    R=strlen(PATTERN);

    while(K<MAX)
    {
        for(;L<R;L++)
        {
            if(PATTERN[L]!=STRING[K+L-1])
            {
                goto step5;
            }
        }
        IND=K;
        return(IND-1);
step5:  K=K+1;
    }
    IND=0;
    return(IND);
}
char* SUBSTRING(char *STRING,int POSITION,int LENGTH)
{
    int J=0,M=0;
    char SUBSTR[90];

    while(J<strlen(STRING))
    {
        if(J==POSITION)
        {
            J=J+LENGTH;
        }
        if(J<strlen(STRING))
        {
             SUBSTR[M]=STRING[J];
             M=M+1;
             J=J+1;
        }
    }
    return(SUBSTR);


}

What is wrong with this code?

char* processIt( /*  */ )
{
    char local_buf[90];
    /* get some stuff into local_buf */
    return loacal_buf; /* Hint! Is this line ok? */
}

Edited 2 Years Ago by David W

This article has been dead for over six months. Start a new discussion instead.