#include "stdio.h"
#include "string.h"
#define SIZE 20
int search(char [],char []);
char* delete(char*,char*,int);
int main()
{
int p=0,i=0,pos=0,s=0,po=0;
char a[SIZE],b[SIZE],d[SIZE],c[SIZE];
printf("enter the string\n");
gets(a);
printf("enter the sub string\n");
gets(b);
strcpy(d,a);
while(p!=-1)
{
p=search(d,b);
if(s{
pos=p+s*strlen(b)+1;
printf("Substring found at position %d\n",pos);
}
s++;
if(p!=-1)
{
strcpy(d,delete(d,b,p));
}
}
if(strcmp(d,a)==0)
printf("Substring not found\n");
else
printf("Substring after deletion is %s\n",d);
}
/*finding substring*/
int search(char *a,char *b)
{
int i=0,j=0,k=0,m,n,pos;
m=strlen(a);
n=strlen(b);
while(i
{
while((a[i]==b[j]) && b[j]!=0)
{
i++;
j++;
}
if (j==n)
{
pos=i-j;
return(pos);
}
else
{
i=i-j+1;
j=0;
}
}
return(-1);
}
/*deleting substring*/
char* delete(char *a,char *b,int pos)
{
int m,i=pos,n;
n=strlen(a);
m=strlen(b);
do
{
a[i]=a[i+m];
i++;
}
while(a[i]!='\0');
return(a);
}
#include "string.h"
#define SIZE 20
int search(char [],char []);
char* delete(char*,char*,int);
int main()
{
int p=0,i=0,pos=0,s=0,po=0;
char a[SIZE],b[SIZE],d[SIZE],c[SIZE];
printf("enter the string\n");
gets(a);
printf("enter the sub string\n");
gets(b);
strcpy(d,a);
while(p!=-1)
{
p=search(d,b);
if(s
No comments:
Post a Comment